2011-04-10 234 views
1

我需要設置一個圖表,開始在當天午夜,只是在第二天的午夜之前結束...... 我試圖做這樣的事情: minChartDate = currentDate.fullYear,currentDate.month,currentDate.date,0,0,0,0;根據其他日期設置日期?

其中currentDate:Date;是天當前選中。

我得到一個數字到日期類型之間的隱式強制錯誤,就像currentDate.fullYear是一個日期,但根據文檔它應該是一個數字。或者是我的語法定義這個不正確?也想知道是否有一個更簡單的方法來獲取最小和最大日期比這個! (我設置這個的原因是它在午夜開始,而不是在系列的第一個數據點)。

我也得到一個奇怪的錯誤'最大'值類型日期不能在文本中表示..它說我需要一個Date類型的對象的最小值和最大值,所以我真的不知道它在說什麼...

回答

1

此代碼將使今天的日期對象設置爲0:00。

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

爲了使一個用於第二天:

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); 

此腳本24小時向前移動的時間對象,然後設置小時,分鐘,秒,milisecs爲0

注意:這不是100%正確的解決方案,因爲夏令時更改而調整小時時,它可能會在幾天內失敗。

+0

您可以在添加24小時之前將d.hours設置爲12來爲夏令時打補丁。這樣,在添加之後,d.hours將是11,12或13,但始終是相同(正確)的一天。 – bart 2011-04-10 09:38:15