JS等价于PHP的“ strtotime('-11 month')”

问题描述 投票:0回答:3

是否有一种简单的方法来获取11个月前的日期,无论是使用Javascript还是涉及JQuery的日期。等效于使用PHP的strtotime('-11 month')。我知道您可以轻松地在JS的Date对象中添加/减去天,但是几个月会稍微复杂一些,而不会涉及到每个月的所有天。

javascript php jquery date strtotime
3个回答
2
投票

也许这会帮到你。

http://phpjs.org/functions/strtotime/

PHPJS是一个了不起的网站,除此以外,还有很多其他功能。而且都是纯JS,没有jQuery。


2
投票

您可以使用moment

moment().subtract('months', 11).toDate()

0
投票

我喜欢php方式,并且将locutus(phpjs)组合成一个小的javascript类/函数作为替代:

http://tools.bitfertig.de/carbonjs/

carbon('-11 month')
© www.soinside.com 2019 - 2024. All rights reserved.