Created
August 4, 2012 15:54
-
-
Save numa08/3258510 to your computer and use it in GitHub Desktop.
Dartで日付の計算をする ref: http://qiita.com/items/2612d3f6114be93e54b2
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
今のバージョンに
Date
はありますか?