D3v4: d3.timeParse fails with UNIX epoch seconds (%s)
NickName:gl03 Ask DateTime:2017-11-01T03:54:58

D3v4: d3.timeParse fails with UNIX epoch seconds (%s)

My dataset includes UNIX timestamps, such as "1509392160". I can't seem to parse those using d3.timeParse("%s"), which returns null.

Checking the reverse process with d3.timeFormat fails me as well. The official example and all other format strings work:

var formatTime = d3.timeFormat("%B %d, %Y");
formatTime(new Date); // -> "June 30, 2015"

However, formatting to UNIX (milli)seconds just returns "s" or "Q" for "%s" and "%Q":

var formatTime = d3.timeFormat("%s");
formatTime(new Date); // -> "s"

Using D3 v4.11.0 btw. What am I missing?

Copyright Notice:Content Author:「gl03」,Reproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/47043555/d3v4-d3-timeparse-fails-with-unix-epoch-seconds-s

Answers
Andrew Reid 2017-10-31T21:22:34

I ran this code with only the d3-time-format module and had no problems:\n\n\r\n\r\nvar parse = d3.timeParse(\"%s\");\r\nvar time = parse(1509392160);\r\n\r\nconsole.log(time);\r\n\r\nvar format = d3.timeFormat(\"%s\");\r\ntime = format(Date.now());\r\n\r\nconsole.log(time);\r\n<script src=\"https://d3js.org/d3-time-format.v2.min.js\"></script>",


More about “D3v4: d3.timeParse fails with UNIX epoch seconds (%s)” related questions

D3v4: d3.timeParse fails with UNIX epoch seconds (%s)

My dataset includes UNIX timestamps, such as "1509392160". I can't seem to parse those using d3.timeParse("%s"), which returns null. Checking the reverse process with d3.timeFormat fails me as wel...

Show Detail

Converting seconds after epoch into unix time

I have seconds (say x, x is long long data type) after epoch. I wish to convert it into unix time using &lt;ctime&gt; library. The issue is, I want a time_t variable for gmtime() to work, I am unab...

Show Detail

How do I get the Unix epoch in seconds for a date without time?

In Go, how do I get the Unix epoch in seconds for a date without time? For example, if I want the Unix epoch seconds for the current time, I can use: today := time.Now().Unix() For instance, if the

Show Detail

Accuracy of unix utc epoch time in seconds in java

I have seen people using System.currentTimeInMillis and converting it into seconds to store unix utc epoch time. But in Java 8 we can also use Instant.ofEpochSeconds. Which one is more accurate? Is...

Show Detail

seconds since the epoch for non-Unix platforms in OCaml

Module Unix contains the time function to get the seconds since the Epoch but is there a platform-independent way to get the same value and ensure the code compiles in non-Unix deployments ?

Show Detail

Ticks between Unix epoch and GPS epoch

What is the number of one second ticks between Unix time epoch (01 Jan 1970) and GPS time epoch (06 Jan 1980)? I have seen multiple answers from several sources on the web. One camp claims the ans...

Show Detail

How to convert a unix timestamp (seconds since epoch) to Ruby DateTime?

How do you convert a Unix timestamp (seconds since epoch) to Ruby DateTime?

Show Detail

Pandas Series: string date to epoch unix seconds

I have a Pandas Dataframe where one column is in a string date format as below 0 time 1 September 20 2016 2 September 20 2016 3 September 19 2016 4 September 16 2016 ...

Show Detail

How to get seconds since unix epoch in Ada?

I feel very stupid as I don't seem to get a plain Natural number representing the seconds since the unix epoch (01/01/1970 00:00:00) in Ada. I've read the Ada.Calendar and it's subpackages up and d...

Show Detail

How to print the number of seconds since unix epoch in solaris shell

Is there a way to use unix date to print the number of seconds since epoch? I'm open to using other standard shell commands if there is a way (I'm using Solaris, so there isn't date "+"%s") Tha

Show Detail