2011-03-11 48 views
1

我有Java代碼這樣的:JavaScript的日曆操作

//first moment of the today 
    Calendar cal = new GregorianCalendar(); 
    cal.set(Calendar.HOUR_OF_DAY, 0); 
    cal.set(Calendar.MINUTE, 0); 
    cal.set(Calendar.SECOND, 0); 
    cal.set(Calendar.MILLISECOND, 0); 

    Calendar tomorrow = (Calendar)cal.clone(); 
    tomorrow.add(Calendar.DAY_OF_YEAR, 1); 

    long time = d.getTime(); 

    // if greater than today's first moment 
    if(time >= tomorrow.getTimeInMillis()){ 
    ... 
    } 
    ... 

我如何使用JavaScript重寫?

回答

1
var cal = new Date(); 
cal.setHours(0); 
cal.setMinutes(0); 
cal.setSeconds(0); 
cal.setMilliseconds(0); 

var tomorrow = new Date(); 

tomorrow.setDate(cal.getDate()+1); 

我要去假設d是你從別的地方有個約會對象:

if (d >= tomorrow) { 

}; 

http://www.w3schools.com/jsref/jsref_obj_date.asp

+2

一些額外的文件,以防萬一(我的首選之一什麼JS :-)):https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Date –

+0

@Neves我接受它作爲你的評論的答案。投票評論你的評論。 – kamaci