0

I have an API which returns date values. Sample value is like 1521441000. When I formatted the date using javascript, I am getting Jan 18 1970 08:07 PM. Also I tried using Javascript Date function. Then also the same reply. Please see the console screen shot. As per the expectation I want this months(March - April 2018) date. Which I am fitering using API call. This is a third party API.I want to confirm is this the problem with API.

enter image description here

Why this is happening. Is this the problem with the date which is returned from the API? Or Is there any problem in my comparison?

1 Answers1

3

1521441000 is time in seconds, you need to multiply that by 1000 to get miliseconds before passing to moment/date constructor:

console.log(new Date(1521441000));
console.log(new Date(1521441000 * 1000));
Martin Adámek
  • 16,771
  • 5
  • 45
  • 64