Skip to content

Instantly share code, notes, and snippets.

@numa08
Created August 4, 2012 15:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save numa08/3258510 to your computer and use it in GitHub Desktop.
Save numa08/3258510 to your computer and use it in GitHub Desktop.
Dartで日付の計算をする ref: http://qiita.com/items/2612d3f6114be93e54b2
void main() {
var start_day = new Date(2012,8,3,0,0,0,0);
var one_week_ago = new Date(2012,8,10,0,0,0,0);
var diff = one_week_ago.difference(start_day);
print(diff.inDays);//7
var difference = difference(start_day, one_week_ago);
print(difference);//5
}
int difference(start,end){
var diff = 0;
while(start < end){
// start の曜日を調べる
var weekday = start.weekday;
// 土曜、日曜でないならdiffを増やす
if(weekday !== Date.SAT && weekday !== Date.SUN){
diff++;
}
// startを1日進める
start = start.add(const Duration(1, 0, 0, 0));
}
return diff;
}
@shinriyo
Copy link

shinriyo commented Jun 2, 2018

今のバージョンにDateはありますか?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment