0

I create the date like this, with a timestamp retrieved from firebase:

let da = new Date(item.date.day);

I have verified that item.date.day is a timestamp, and the correct timestamp.

However, it always creates the date:

Sun Jan 18 1970 03:53:45 GMT-0500 (EST)

No matter what the timestamp is. I have checked the timestamps here, here they are:

1500825600 1499097600 1500134400 1501084800

They are all dates in July as they should be (these are the values for item.date.day).

Extremely bizarre. Any help is much needed and appreciated.

1
  • 1
    Multiple by 1000: you're storing them in seconds, but Date expected milliseconds. new Date(1500825600*1000) => Sun Jul 23 2017 09:00:00 GMT-0700 (PDT) Commented Jul 26, 2017 at 20:35

1 Answer 1

4

In JavaScript, new Date(value) expects value to be in milliseconds since "1 January 1970 00:00:00".

If you multiply your unix timestamps (seconds since "1 January 1970 00:00:00") with 1000, you will get the correct results.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.