最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - get tomorrows date with jquery and compare - Stack Overflow

programmeradmin2浏览0评论

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

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

Share Improve this question asked Sep 26, 2013 at 10:09 dev1234dev1234 5,71616 gold badges61 silver badges118 bronze badges 7
  • 3 Comparing dates in JS is a nightmare. Use date.js to simplify it. – Rory McCrossan Commented Sep 26, 2013 at 10:13
  • 1 @RoryMcCrossan ok. but how to get only date from this ? Fri Sep 27 2013 15:19:01 GMT+0530 (Sri Lanka Standard Time) – dev1234 Commented Sep 26, 2013 at 10:14
  • 1 Why would you want to use jquery, a dom manipulation library, to compare dates – Lepidosteus Commented Sep 26, 2013 at 10:17
  • 1 @mazraara check on the documentation of date.js, specifically the toString() method. – Rory McCrossan Commented Sep 26, 2013 at 10:19
  • 1 @Lepidosteus is there any other possibility ? – dev1234 Commented Sep 26, 2013 at 10:19
 |  Show 2 more comments

4 Answers 4

Reset to default 8

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/

Moment.js will do that for you very easily.

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

I would use the DateJS library.

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

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());
发布评论

评论列表(0)

  1. 暂无评论