2011-03-11 136 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