James
James

Reputation: 818

MomentJS set timezone

Because of how we store dates I need to set a moment object to timezone +0000.

I've tried using a variety of ways:

var d = moment().hour(0).minute(0).second(0).millisecond(0).zone('+0000');
var d = moment().hour(0).minute(0).second(0).millisecond(0).utc(0);
var d = moment().hour(0).minute(0).second(0).millisecond(0).utc();

When I console.log these dates they come out with the time 00:00:00 GMT+0100 (BST)

Looking at the documentation it seems to say that .utc() and .zone() are for printing a format only, is this true? (This is the same I've seen with other questions on here, none address setting the actual object to a timezone it seems)

After I set and then manipulate the date I convert it to the JS Date object to use with angular-ui bootstrap datepicker (note: it was a moment object which I used console.log on).

Upvotes: 0

Views: 22959

Answers (1)

Wédney Yuri
Wédney Yuri

Reputation: 1277

Unless you specify a timezone offset, parsing a string will create a date in the current timezone. http://momentjs.com/docs/#/parsing/string-format/

Example: You can tell in which timezone is your date using moment ('2015-05-06T23:00:00.000Z').

If you need to convert this to a specific timezone you can do so: moment().utc(0).format('YYYY-MM-DD HH:mm Z').

About Timezone in Javascript: How do I specify the time zone when creating a JavaScript Date?

Upvotes: 6

Related Questions