使用 jquery 获取明天的日期并进行比较

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/19025330/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-26 23:02:38  来源:igfitidea点击:

get tomorrows date with jquery and compare

javascriptjquerydatedatetime

提问by dev1234

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

如何以这种格式获取日期?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.

我需要看看天气,给定的日期是明天。像这样的事情,当我给 28/09/2013 时,它应该像明天一样提醒。

any help is highlight appreciated.

任何帮助都值得赞赏。

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

注意:我只需要与日期进行比较。28/09/2013 === 明天

回答by Silviu Burcea

Moment.jswill do that for you very easily.

Moment.js会很容易地为你做到这一点。

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

回答by Nishu Tayal

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/

这是演示:http: //jsfiddle.net/5Yj3V/3/

回答by Nadeem_MK

I would use the DateJS library.

我会使用DateJS 库

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

回答by Saranya Sadhasivam

Try the below fiddleusing javascript.

使用 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());