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 badges
Add a ment  | 

1 Answer 1

Reset to default 13

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

本文标签: javascriptmomentjs specific format with timezoneStack Overflow