TimezoneJS.Date
A timezone-enabled, drop-in replacement for the stock JavaScript Date. The timezoneJS.Date
object is API-compatible with JS Date, with the same getter and setter methods -- it should work fine in any code that works with normal JavaScript Dates.
Overview
The timezoneJS.Date
object gives you full-blown timezone support, independent from the timezone set on the end-user's machine running the browser. It uses the Olson zoneinfo files for its timezone data.
The constructor function and setter methods use proxy JavaScript Date objects behind the scenes, so you can use strings like '10/22/2006' with the constructor. You also get the same sensible wraparound behavior with numeric parameters (like setting a value of 14 for the month wraps around to the next March).
The other significant difference from the built-in JavaScript Date is that timezoneJS.Date
also has named properties that store the values of year, month, date, etc., so it can be directly serialized to JSON and used for data transfer.
Setup
This section shows the most common way of setting up timezone-js. In the 'Customizing' section below you can find alternative approaches.
First you'll need to include the code on your page. Both timezoneJS.Date
, and the supporting code it needs in timezoneJS.timezone
are bundled in the date.js
file in src
directory. Include the code on your page with a normal JavaScript script include, like so: