1
votes

how is it possble to get the date in this format ? 28/09/2013

what i am getting now is,

Fri Sep 27 2013 15:19:01 GMT+0530 (Sri Lanka Standard Time)

This is the code i have written to get that..

 var date = new Date();
 var tomorrow = new Date(date.getTime() + 24 * 60 * 60 * 1000);
 alert(tomorrow);

and i need to see weather, is the given date is tomorrow. something like this when i give 28/09/2013 it should alert as tomorrow or not.

any help is highlight appreciated.

NOTE : i only need to compare with date. 28/09/2013 === tomorrow

4
Comparing dates in JS is a nightmare. Use date.js to simplify it.Rory McCrossan
@RoryMcCrossan ok. but how to get only date from this ? Fri Sep 27 2013 15:19:01 GMT+0530 (Sri Lanka Standard Time)dev1234
Why would you want to use jquery, a dom manipulation library, to compare datesLepidosteus
@mazraara check on the documentation of date.js, specifically the toString() method.Rory McCrossan
@Lepidosteus is there any other possibility ?dev1234

4 Answers

4
votes

I would use the DateJS library.

var tomorrow = new Date.today().addDays(1).toString("dd-mm-yyyy"); 
7
votes

You can try following to get the next day :

var myDate=new Date();
myDate.setDate(myDate.getDate()+1);
// format a date
var dt = myDate.getDate() + '/' + ("0" + (myDate.getMonth() + 1)).slice(-2) + '/' + myDate.getFullYear();
console.log(dt);

Here is the demo : http://jsfiddle.net/5Yj3V/3/

6
votes

Moment.js will do that for you very easily.

moment().add('days', 1).format('L');
1
votes

Try the below fiddle using javascript.

var tomorrow = new Date(); 
var newdate = new Date();
var month = (newdate.getMonth()+1);
newdate.setDate(tomorrow.getDate() + 1);
if (month < 10)
{
    month = '0' + (newdate.getMonth()+1);
}

alert(newdate);
alert(newdate.getDate() + '/' + month + '/' + newdate.getFullYear());