admin管理员组文章数量:1279019
I'm trying to both parse and format a date with the format given to me by my server guys as
yyyy-MM-dd,HH:mm:ss.sssZ
2014-05-09,09:00:00.000-0400
Using moment.js, I can parse a provided date via
moment(date, "YYYY-MM-DD,HH:mm:ss.sssZ")
This seems to work okay, however if I were to add .format("YYYY-MM-DD,HH:mm:ss.sssZ")
I get:
2014-04-30,09:00:00.000-04:00
For the most part this is okay, but notice the colon in the timezone spot. It should be -0400
, not -04:00
. I can easily strip off the colon, but before I resort to that, is there any other format string I should be using for parsing and formatting the dates?
I've also tried including moment-timezone.js, but this doesn't make any difference.
I'm trying to both parse and format a date with the format given to me by my server guys as
yyyy-MM-dd,HH:mm:ss.sssZ
2014-05-09,09:00:00.000-0400
Using moment.js, I can parse a provided date via
moment(date, "YYYY-MM-DD,HH:mm:ss.sssZ")
This seems to work okay, however if I were to add .format("YYYY-MM-DD,HH:mm:ss.sssZ")
I get:
2014-04-30,09:00:00.000-04:00
For the most part this is okay, but notice the colon in the timezone spot. It should be -0400
, not -04:00
. I can easily strip off the colon, but before I resort to that, is there any other format string I should be using for parsing and formatting the dates?
I've also tried including moment-timezone.js, but this doesn't make any difference.
Share Improve this question asked Apr 29, 2014 at 13:39 Explosion PillsExplosion Pills 192k55 gold badges340 silver badges416 bronze badges1 Answer
Reset to default 13The moment.js documentation says use ZZ instead of Z in your format string.
本文标签: javascriptmomentjs specific format with timezoneStack Overflow
版权声明:本文标题:javascript - moment.js specific format with timezone - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741233496a2362547.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论