[英]Moment.js returning wrong date
I'm trying to use moment to convert Date-Time for October 29th, 2013 with this format 我正试图利用这种格式将时间转换为2013年10月29日的日期时间
2013-10-29T00:00:00.000Z
However when I do this 但是,当我这样做
moment('2013-10-29T00:00:00.000Z').format("MMM Do, YYYY")
It returns October 28th, 2013 when it should return October 29th, 2013 它将于2013年10月28日返回,届时将于2013年10月29日返回
If you have some ideas on how I can solve this issue, please let me know. 如果您对如何解决此问题有一些想法,请告诉我。 Thank you
谢谢
If you want the time in utc, use: 如果你想在utc中使用时间,请使用:
moment.utc('2013-10-29T00:00:00.000')
As @MattJohnson pointed out, using the moment
constructor will translate it to local time. 正如@MattJohnson指出的那样,使用
moment
构造函数会将其转换为当地时间。 Instead (if you don't want to use the utc
method), you can replace the Z
with +0
. 相反(如果您不想使用
utc
方法),可以用+0
替换Z
See options for string date/time http://momentjs.com/docs/#/parsing/string-format/ 请参阅字符串日期/时间的选项http://momentjs.com/docs/#/parsing/string-format/
You can adjust the timezone settings by doing this: 您可以通过执行以下操作来调整时区设置:
moment('2013-10-29T00:00:00.000Z').zone(0).format("MMM Do, YYYY");
Going to go ahead and add Matt's suggestion as well, since it is more semantic. 继续前进并添加Matt的建议,因为它更具语义性。
moment('2013-10-29T00:00:00.000Z').utc().format("MMM Do, YYYY");
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.