Fetching contributors…
Cannot retrieve contributors at this time
77 lines (59 sloc) 3.09 KB
title signature
Parsing in Zone, String);

The constructor takes all the same arguments as the moment constructor, but uses the last argument as a time zone identifier.

var a ="2013-11-18 11:55", "America/Toronto");
var b ="May 12th 2014 8PM", "MMM Do YYYY hA", "America/Toronto");
var c =, "America/Toronto");
a.format(); // 2013-11-18T11:55:00-05:00
b.format(); // 2014-05-12T20:00:00-04:00
c.format(); // 2014-06-22T12:21:08-04:00

This constructor is DST aware, and will use the correct offset when parsing."2013-12-01", "America/Los_Angeles").format(); // 2013-12-01T00:00:00-08:00"2013-06-01", "America/Los_Angeles").format(); // 2013-06-01T00:00:00-07:00

The offset is only taken into consideration when constructing with an array, string without offset, or object.

var arr = [2013, 5, 1],
    str = "2013-12-01",
    obj = { year : 2013, month : 5, day : 1 };, "America/Los_Angeles").format(); // 2013-06-01T00:00:00-07:00, "America/Los_Angeles").format(); // 2013-12-01T00:00:00-08:00, "America/Los_Angeles").format(); // 2013-06-01T00:00:00-07:00, "America/New_York").format();    // 2013-06-01T00:00:00-04:00, "America/New_York").format();    // 2013-12-01T00:00:00-05:00, "America/New_York").format();    // 2013-06-01T00:00:00-04:00

If the input string contains an offset, it is used instead for parsing. The parsed moment is then converted to the target zone.

var zone = "America/Los_Angeles";'2013-06-01T00:00:00',       zone).format(); // 2013-06-01T00:00:00-07:00'2013-06-01T00:00:00-04:00', zone).format(); // 2013-05-31T21:00:00-07:00'2013-06-01T00:00:00+00:00', zone).format(); // 2013-05-31T17:00:00-07:00

Unix timestamps and Date objects refer to specific points in time, thus it doesn't make sense to use the time zone offset when constructing. Using|Date, zone) is functionally equivalent to moment(Number|Date).tz(zone).

var timestamp = 1403454068850,
    date = new Date(timestamp);, "America/Los_Angeles").format(); // 2014-06-22T09:21:08-07:00
moment(timestamp).tz("America/Los_Angeles").format(); // 2014-06-22T09:21:08-07:00, "America/Los_Angeles").format();      // 2014-06-22T09:21:08-07:00
moment(date).tz("America/Los_Angeles").format();      // 2014-06-22T09:21:08-07:00

Уou may specify a boolean right after format argument to use strict parsing. Strict parsing requires that the format and input match exactly, including delimeters.'It is 2012-05-25', 'YYYY-MM-DD', "America/Toronto").isValid();       // true'It is 2012-05-25', 'YYYY-MM-DD', true, "America/Toronto").isValid(); // false'2012-05-25', 'YYYY-MM-DD', true, "America/Toronto").isValid();       // true'2012-05.25', 'YYYY-MM-DD', true, "America/Toronto").isValid();       // false