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.

有帮助吗?

解决方案

The moment.js documentation says use ZZ instead of Z in your format string.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top