开发者

Set a date based on other dates?

I need to set a chart to start at midnight of the current day and end just before midnight of the next day... I'm trying to do something like this: minChartDate = currentDate.fullYear,currentDate.month,currentDate.date,0,开发者_如何学JAVA0,0,0;

where currentDate:Date; is the day currently selected.

I'm getting an implicit coercion error between the Number to Date type, as if currentDate.fullYear is a Date, but according to the documentation it should be a number. Or is my syntax defining this incorrect? Also wondering if there's a simpler way to get the min and max dates than this! (the reason I am setting this is so that it starts at midnight rather than at the first data point in the series).

I'm also getting a weird error 'maximum' values of type Date cannot be represented in text.. it said I need a Date type object for the minimum and maximum so I'm really not sure what it's talking about...


this code will make a date object set to 0:00 on today.

var minChartdate:Date= new Date();
minChartdate.hours=0;
minChartdate.minutes=0;
minChartdate.seconds=0;
minChartdate.milliseconds=0;
trace(minChartdate)

To make one for the next day:

var minChartdate:Date= new Date();
minChartdate.time = minChartdate.time+1000*60*60*24 // one day in milliseconds
minChartdate.hours=0;
minChartdate.minutes=0;
minChartdate.seconds=0;
minChartdate.milliseconds=0;
trace(minChartdate);

This script moves the date object forward by 24 hours, and then sets hours, mins,sec,milisecs to 0.

Note: This is not 100% correct solution, it can fail on days, when the hours are adjusted because of daylight saving time changes.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜