Moment Timezone0.0.5

Documentation

#Where to use it

In order to use moment-timezone, you will need moment@2.6.0 or greater, the core moment-timezone library, and the moment-timezone data.

You can use the data builder at momentjs.com/timezone/data/ to construct a data set with only the zones needed.

#Node.js

npm install moment-timezone
var moment = require('moment-timezone');
moment().tz("America/Los_Angeles").format();

#Browser

<script src="moment.js"></script>
<script src="moment-timezone.js"></script>
<script src="moment-timezone-data.js"></script>
<script>
    moment().tz("America/Los_Angeles").format();
</script>

#Require.js

require.config({
    paths: {
        "moment": "path/to/moment",
        "moment-timezone": "path/to/moment-timezone",
        "moment-timezone-data": "path/to/moment-timezone-data"
    }
});
define(["moment-timezone", "moment-timezone-data"], function (moment) {
    moment().tz("America/Los_Angeles").format();
});

#Constructor

moment.tz(..., String);

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

moment.tz("2013-11-18 11:55", "America/Toronto").format(); // "2013-11-18T11:55:00-05:00"
moment.tz(new Date(2013, 11, 18), "America/Toronto").format(); // "2013-12-18T00:00:00-05:00"

#Mutator

moment(...).tz(String);

The .tz mutator will set the timezone to the provided time zone identifier and update the offset.

moment("2013-11-18").tz("America/Toronto").zone(); // 300
moment("2013-11-18").tz("Europe/Berlin").zone(); // -60

This information is used consistently in other operations, like calculating the start of the day.

var m = moment("2013-11-18 11:55");
m.tz("America/Toronto").format(); // "2013-11-18T11:55:00-05:00"
m.startOf("day").format(); // "2013-11-18T00:00:00-05:00"
m.tz("Europe/Berlin").format(); // "2013-11-18T06:00:00+01:00"