0

I am trying to parse date with my specific timezone - not utc or browser. I am using

d3.timeFormat("%H:%M %p");

but this function is unsing browser timezone automatically.

d3.utcFormat("%H:%M %p"); // is using utc

I am thinking about using moment.js but don't know how. Any idea?

------UPDATE---------------------------------------

I am using unix timestamps as number to do linear scaling.

   var xScale = d3.scaleLinear()
        .range([0, width])
        .domain([minTime, maxTime]);

and just parsing it when display it

   var xAxis = d3.axisBottom()
        .scale(xScale)
        .ticks(7)
        .tickFormat(d3.timeFormat("%H:%M %p"));

so input is e.g. 1647245248 and I want to set timezones that I get from moment.js list.

So I need to add timezone in data in unix timestamp or just in d3 display axis.

Robin Mackenzie
  • 18,801
  • 7
  • 38
  • 56
13Akaren
  • 225
  • 3
  • 16
  • Your question is unclear. Are you trying to **parse** a date string? Your code shows date **formatters** that are used for formatting date objects. What is your input, dates or date strings? – altocumulus Mar 17 '22 at 13:58
  • my input is string - unix timestamp – 13Akaren Mar 17 '22 at 17:56
  • I think some things might have gotten mixed up in this question... A Unix time stamp would be a mere number of seconds that could be passed directly to the [`Date`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/Date) constructor. That number inherently refers to UTC, though. Try to be as specific as possible when describing your problem. Please show an example of your input data string, describe what you are trying to do and what exactly does not work. What is your expected result? Are you trying to convert a time instance between different time zones? – altocumulus Mar 17 '22 at 18:30
  • I have updated my question – 13Akaren Mar 17 '22 at 21:32
  • Does this answer your question? [Time axis in d3.js with specific time zone](https://stackoverflow.com/questions/33388547/time-axis-in-d3-js-with-specific-time-zone) – Robin Mackenzie Mar 20 '22 at 12:32

0 Answers0