setDate无法在批处理脚本的eval中正确设置日期 [英] setDate not setting date properly inside eval in batch script

查看:71
本文介绍了setDate无法在批处理脚本的eval中正确设置日期的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

-eval"var date = new Date(); date.setDate(date.getDate()-10)"' 暂停

--eval "var date = new Date(); date.setDate(date.getDate()-10)"' pause

new Date()给我当前日期.我想获取10天的日期,但是setDate()不能正确设置日期.我正在通过批处理脚本进行操作. 我在评估date.setDate(date.getDate()-10)后得到了1576031482772.请帮助我找到解决方案.

new Date() gives me the current date. I'm trying to get 10 days back date,but setDate() not setting the date correctly.I'm doing it through batch script. I got this 1576031482772 after evaluating date.setDate(date.getDate()-10) .Please help me find a solution.

推荐答案

这是预期的行为. setDate的签名如下. 参考

This is the expected behavior. The signature of setDate is as follows. ref

参数

它接受一个参数,它应该是数字作为日值.

It accepts one parameter, it should be number as a day value.

返回值

它返回1970年1月1日UTC和给定日期之间的毫秒数

It returns milliseconds between 1 January 1970 00:00:00 UTC and the given date

解决方案

您实际上是在设置日期的日期值.因此,如果要检索该值,请使用date.getDate().这将是新日期.

You are actually setting the day value of date. So If you want to retrieve the value, just use date.getDate(). Which will be the new date.

有关更多详细信息,它是如何工作的,您可以参考

For more details, how it works, you can refer MDN.

这篇关于setDate无法在批处理脚本的eval中正确设置日期的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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