Moment.js返回错误的日期 [英] Moment.js returning wrong date

查看:571
本文介绍了Moment.js返回错误的日期的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正尝试用这种格式转换2013年10月29日的日期时间。

I'm trying to use moment to convert Date-Time for October 29th, 2013 with this format

2013-10-29T00:00:00.000Z

但是当我这样做

moment('2013-10-29T00:00:00.000Z').format("MMM Do, YYYY")

它将返回 2013年10月28日,当它返回 2013年10月29日

如果您有一些关于我如何解决这个问题的想法,请让我知道。谢谢

If you have some ideas on how I can solve this issue, please let me know. Thank you

推荐答案

如果您想在utc中使用时间,请使用:

If you want the time in utc, use:

moment.utc('2013-10-29T00:00:00.000')

正如@MattJohnson指出的,使用时刻构造函数将会将其转换为本地时间。相反(如果您不想使用 utc 方法),则可以将 Z 替换为 +0 。查看字符串日期/时间的选项 http://momentjs.com/docs/#/parsing / string-format /

As @MattJohnson pointed out, using the moment constructor will translate it to local time. Instead (if you don't want to use the utc method), you can replace the Z with +0. See options for string date/time http://momentjs.com/docs/#/parsing/string-format/

这篇关于Moment.js返回错误的日期的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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