Moment Locale Not Set Correctly
We're trying to find a problem with tests that use moment.js and fail when run on a server in Arizona but succeed when run locally here in the UK. We manually set the locale before
Solution 1:
Locale and timezone are orthogonal things. A locale does not specify a timezone unambigously. You need to set your timezone separately. You can use Momemt Timezone, and then you can use e.g.
.tz('Europe/London')
Solution 2:
By setting moment.locale('en-gb')
you have specified a locale/language (brittish-english), not a timezone.
To specify a timezone you need to include the Moment.js Timezone library in your project, and then do something like:
console.log(moment('2016-05-01T00:00:00+00:00').tz('America/Phoenix').format());
The above will give you the timezone for Arizona.
Solution 3:
After reading more I believe parseZone is the correct solution, given that I am already including Time Zone information in the date string.
console.log(moment.parseZone('2016-05-01T00:00:00+00:00').format());
Post a Comment for "Moment Locale Not Set Correctly"