如何用Momentjs获取昨天的日期? [英] How to get yesterday's date with Momentjs?
本文介绍了如何用Momentjs获取昨天的日期?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
所以,我的问题很简单,如何获得MomentJs的昨天约会? 在Javascript中,这非常简单,即
So, my question is simple, how do I get yesterday's date with MomentJs ? In Javascript it is very simple, i.e.
today = new Date();
yesterday = new Date(today.setDate(today.getDate() - 1))
console.log(yesterday)
但是我如何通过MomentJs实现呢?
But how do I achieve this with MomentJs ?
推荐答案
就像这样:moment().subtract(1, 'days')
.它将为您提供前一天的本地计算机上相同的确切当前时间.
Just like this: moment().subtract(1, 'days')
. It will give you the previous day with the same exact current time that is on your local pc.
这篇关于如何用Momentjs获取昨天的日期?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文