UTC1.5.0+

  1. moment.utc();
  2. moment.utc(Number);
  3. moment.utc(Number[]);
  4. moment.utc(String);
  5. moment.utc(String, String);
  6. moment.utc(String, String[]);
  7. moment.utc(String, String, String);
  8. moment.utc(String, String, Boolean);
  9. moment.utc(String, String, String, Boolean);
  10. moment.utc(Moment);
  11. moment.utc(Date);

By default, moment parses and displays in local time.

If you want to parse or display a moment in UTC, you can use moment.utc() instead of moment().

This brings us to an interesting feature of Moment.js. UTC mode.

While in UTC mode, all display methods will display in UTC time instead of local time.

  1. moment().format(); // 2013-02-04T10:35:24-08:00
  2. moment.utc().format(); // 2013-02-04T18:35:24+00:00

Additionally, while in UTC mode, all getters and setters will internally use the Date#getUTC and Date#setUTC methods instead of the Date#get and Date#set methods.

  1. moment.utc().seconds(30).valueOf() === new Date().setUTCSeconds(30);
  2. moment.utc().seconds() === new Date().getUTCSeconds();

It is important to note that though the displays differ above, they are both the same moment in time.

  1. var a = moment();
  2. var b = moment.utc();
  3. a.format(); // 2013-02-04T10:35:24-08:00
  4. b.format(); // 2013-02-04T18:35:24+00:00
  5. a.valueOf(); // 1360002924000
  6. b.valueOf(); // 1360002924000

Any moment created with moment.utc() will be in UTC mode, and any moment created with moment() will not.

To switch from UTC to local time, you can use moment#utc or moment#local.

  1. var a = moment.utc([2011, 0, 1, 8]);
  2. a.hours(); // 8 UTC
  3. a.local();
  4. a.hours(); // 0 PST