0

I am storing Unix Timestamp in Firebase server and it is saving as 1417780144675.

When I am converting epochconverter the output is:

Assuming that this timestamp is in milliseconds:
GMT: Fri, 05 Dec 2014 11:49:04 GMT
Your time zone: 12/5/2014, 5:19:04 PM GMT+5:30

But when I am converting in JavaScript, the output is:

Fri Aug 30 46897 15:27:55 GMT+0530 (IST)

So output from epochconverter is correct whereas in JavaScript it's coming wrong.

Please how to get correct output using JavaScript.

Frank van Puffelen
  • 565,676
  • 79
  • 828
  • 807
RubyOnRails
  • 235
  • 1
  • 15
  • 1
    Show us your JavaScript code please. We cannot say what you're doing wrong without seeing what you're doing. – Frank van Puffelen Dec 05 '14 at 13:42
  • Keep in mind that this type of question has been covered extensively here on StackOverflow. E.g. http://stackoverflow.com/questions/23483787/convert-unix-timestamp-with-a-timezone-to-javascript-date?rq=1 – Frank van Puffelen Dec 05 '14 at 13:45
  • 2
    My guess is that you're looking for: `new Date(1417780144675).toUTCString()`, which returns "Fri, 05 Dec 2014 11:49:04 GMT" (like the middle line of epochconverter). – Frank van Puffelen Dec 05 '14 at 13:48
  • @FrankvanPuffelen, Thank you i have did in my code var datetime = new Date(data.created_at * 1000); Now its working fine with var datetime = new Date(data.created_at); – RubyOnRails Dec 06 '14 at 04:56
  • Good to hear that you got it working. Next time be sure to include such a code snippet in your question, without it we're playing a guessing game. – Frank van Puffelen Dec 06 '14 at 13:30

1 Answers1

3

You should instanciate a new Date:

var date = new Date(1417780144675);

Output:

Fri Dec 05 2014 12:49:04 GMT+0100 
Kutyel
  • 8,575
  • 3
  • 30
  • 61
  • Okay thank you i did like this var datetime = new Date(data.created_at * 1000); multiplied with 1000. Now it's working fine... – RubyOnRails Dec 06 '14 at 04:58