0

Using MomentJS + ReactJS: Currently I have the following but it accepts the value as local time.

How can I have it accept the value as UTC date/time and not local date/time?

var dateTime = new Date("11 30 2016 00:00:00")
//Logs as: `Wed Nov 30 2016 00:00:00 GMT-0800 (PST)` but would want it to just accept the value as is in GMT/UTC rather than PST, local date/time/

Will be sure to upvote. Thank you

Rob
  • 14,746
  • 28
  • 47
  • 65
Dan Me
  • 2,143
  • 4
  • 19
  • 19

1 Answers1

0

You're creating a new native javascript Date object instead of a "Moment" instance.

Since you're using Moment, you probably want to use moment.utc() instead. There is documentation here on the method.

In your instance:

var time = moment.utc("11-30-2016 00:00:00");

  • I recall being able to do like new Date("..." + "UTC"), do you know which I'm referring to? – Dan Me Dec 12 '16 at 23:07
  • Actually gave what you suggested a try, and it console logged the following: `1480464000000`. I would like it to return `Wed Nov 30 2016 00:00:00 GMT` rather, and not in PST. – Dan Me Dec 13 '16 at 01:13
  • You can use `time.toString()` to get it in that format. You can sometimes use `new Date('...' + 'Z')` to set it to UTC (Zulu) time, but that doesn't work in all browsers. –  Dec 13 '16 at 03:50