Flex: adding 1 day to a specific date
how can i set a date adding 1 开发者_Go百科day in flex??
Isn't Flex based on ECMA (basically javascript), if so, try just adding 86400000 milliseconds to the date object? Something like:
var mili = 1000;
var secs = 60;
var mins = 60;
var hours = 24;
var day = hours * mins * secs * mili;
var tomorrow = new Date();
var tomorrow.setTime(tomorrow.getTime() + day);
tommorow date arithmetic suggested by @Treby can be uses this way by using Date(year, month, day) constructor :
var now:Date = Date();
var currentDate = now.date;
var currentMonth = now.month;
var currentYear = now.fullYear;
var tomorrow:Date = new Date(currentYear, currentMonth, currentDate + 1);
var lastWeek:Date = new Date(currentYear, currentMonth, currentDate - 7);
var lastMonth:Date = new Date(currentYear, currentMonth-1, currentDate);
etc.
Use:
var date:Date = new Date();
date.setDate(date.getDate() + 1);
As this considers the summer timechange days, when days have 23h or 25h.
Cheers
I took this helper function from this blog post, but it's just a snippet.
The usage is simple:
dateAdd("date", +2); //now plus 2 days
then
static public function dateAdd(datepart:String = "", number:Number = 0, date:Date = null):Date
{
if (date == null) {
date = new Date();
}
var returnDate:Date = new Date(date.time);;
switch (datepart.toLowerCase()) {
case "fullyear":
case "month":
case "date":
case "hours":
case "minutes":
case "seconds":
case "milliseconds":
returnDate[datepart] += number;
break;
default:
/* Unknown date part, do nothing. */
break;
}
return returnDate;
}
or if you are after a fancy solution you can use the library Flex Date Utils http://flexdateutils.riaforge.org/, which has a lot of useful operations
best
精彩评论