从日期我只想在 javascript/angularjs 中减去 1 天 [英] from Date I just want to subtract 1 day in javascript/angularjs

查看:33
本文介绍了从日期我只想在 javascript/angularjs 中减去 1 天的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在 new Date() 的帮助下,我如何实现这一目标.我的代码:

with the help of new Date() how i can achieve this. my code :

var temp =new Date("October 13, 2014 22:34:17");
console.log(new Date(temp-1));

要求:

before: Aug 4, 2014 11:59pm (EDT)
after:   Aug 3, 2014 11:59pm (EDT)

推荐答案

您需要指定要减去的时间量.目前它是 1,但 1 是什么?因此,尝试使用 getDate() 获取日期,然后从中减去,然后使用 setDate() 设置日期.

You need to specify what amount of time you are subtracting. At the moment its 1, but 1 what? Therefore, try getting the days using getDate() and then subtract from that and then set the date with setDate().

例如

var temp = new Date("October 13, 2014 22:34:17");
temp.setDate(temp.getDate()-1);

这篇关于从日期我只想在 javascript/angularjs 中减去 1 天的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆