Javascript 如何在 TypeScript 中为日期添加一天
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/42261302/
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
How to add a day to a date in TypeScript
提问by Joe
I need to add 1 day to a date variable in TypeScript. May I know how can I add a day to a date field in TypeScript.
我需要在 TypeScript 中为日期变量添加 1 天。我可以知道如何在 TypeScript 的日期字段中添加一天。
回答by Adam
This is just regular JavaScript, no need for TypeScript.
这只是普通的 JavaScript,不需要 TypeScript。
yourDate = new Date(yourDate.getTime() + (1000 * 60 * 60 * 24));
1000 milliseconds in a second * 60 seconds in a minute * 60 minutes in an hour * 24 hours.
一秒 1000 毫秒 * 一分钟 60 秒 * 一小时 60 分钟 * 24 小时。
Additionally you could increment the date:
此外,您可以增加日期:
yourDate.setDate(yourDate.getDate() + 1);
回答by RK_Aus
addDays(date: Date, days: number): Date {
date.setDate(date.getDate() + days);
return date;
}
In your case days = 1
在您的情况下,天数 = 1

![Javascript Chrome 违规:[违规] 处理程序占用了 83 毫秒的运行时间](/res/img/loading.gif)