I am using d3.time.scale()
(reference here) to create time scale and providing tick values using axis.tickValues([values])
(here). The ticks are rendered for the specified Date objects provided in [values].
All fine, but the tick values representations are always in current time zone of the browser. Now comes the requirement to show it in a specific time zone (say, 'Asia/Calcutta'). Is there a way to achieve this? The max option I see is for formatting the ticks, but not replacing them with custom values, which doesn't help the case.
EDIT: This might be achieved using an external library like moment.js, but it is preferred if this could be avoided.
Timezones are such a pain in the ass. But if you couple
d3
with the the excellent moment timezone, this task becomes pretty easy with atickformatter
function:Here's a full working example:
Based on the solution by Mark, here is a working solution without using external library. Enter the Time zone id (e.g. - Europe/Berlin) in the text field.