kamaci
kamaci

Reputation: 75127

JavaScript Calendar Operations

I have Java code like that:

  //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()){
  ...
  }
  ...

How can I rewrite it with JavaScript?

Upvotes: 1

Views: 658

Answers (1)

dting
dting

Reputation: 39287

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

i'm going to assume d is a date object you got from somewhere else:

if ( d >= tomorrow ) {

};

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

Upvotes: 1

Related Questions