Accepted answer

D3 v4 time format has support for custom locales, but I don't see anything for time zones (so you can show the date-time in Russian, but only with the browser's local time zone), which is understandable, as it requires having the TZ data locally.

The only way I see is to bring another library.
Edit: no wait, Date.toLocaleString supports timeZone parameter (but it seems browser support is limited, e.g. Android does not support this (well, Chrome does, Firefox does not, and maybe WebViews won't)):

new Date(1502769000000).toLocaleString('en-US', { timeZone: 'America/New_York' })
// 8/14/2017, 11:50:00 PM"

(so you'd just need to add the "EDT" suffix yourself)

Alternatively, with moment-timezone (which itself requires moment):

var t = 1502769000000;
var f = 'M/D/Y h:mma z';
// 8/14/2017 11:50pm EDT
// 8/15/2017 5:50am CEST

Since you always need the same TZ, you might be interested to note that it's also technically possible to build a lighter version yourself with only the subset of TZ data you require.


The toString() method on a regular javascript Date object includes the time zone abbreviation but the d3-time-format library doesn't seem to include a way to get it.

var date = new Date(123456789);
console.log(date.toString()); //"Fri Jan 02 1970 05:17:36 GMT-0500 (EST)"

var d3Format = d3.timeFormat("%c %Z");
console.log(d3Format(date)); //"1/2/1970, 5:17:36 AM -0500"

So you'll have to add in the time zone abbreviation manually with your own function.

var jenny = new Date(8675309);
var d3Format = d3.timeFormat("%c"); //%c is shorthand for %x %X (date and time)

// Add "EST" to the end of every string
var addEST = function(date) {
    return d3Format(date) + " EST";

console.log(addEST(jenny)); //"12/31/1969, 9:24:35 PM EST"

Related Query