简体   繁体   English

使用Moment.js在当前时间之前24小时/ 1天获取时间

[英]Get time 24 hours / 1 day before current time using Moment.js

To get the current time in UTC format, I can use 要以UTC格式获取当前时间,我可以使用

moment.utc().format("YYYY-MM-DD HH:mm:ss");

Now, in Moment.js, how do I get the time in the same format but 24 hours before that? 现在,在Moment.js中,如何在24小时之前以相同的格式获取时间?

moment.utc().subtract(1,"day").format("YYYY,MM-DD HH:mm:ss");

要么

moment.utc().subtract(24,"hours").format("YYYY,MM-DD HH:mm:ss");

使用subtract来做到这一点。

moment().subtract(24, 'hours').utc().format("YYYY-MM-DD HH:mm:ss");

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM