1

How can I convert a UTC timestamp to human readable time - using JavaScript?

For instance, I have this timestamp - 1425356823380

I would like to convert it to this format,

03/03/2015 04:27:03

This is how I get the timestamp from,

var d = new Date();
var utc = d.getTime() + (d.getTimezoneOffset() * 60000);

Any ideas?

Run
  • 54,938
  • 169
  • 450
  • 748
  • 1
    `new Date(1425356823380).toLocaleString()` ? Plenty of other methods here if that doesn't suit - https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/prototype#Methods – Phil Mar 03 '15 at 04:34
  • 1
    Use a library like moment.js http://momentjs.com/ – wrshawn Mar 03 '15 at 04:38
  • 1
    possible duplicate of [Where can I find documentation on formatting a date in JavaScript](http://stackoverflow.com/questions/1056728/where-can-i-find-documentation-on-formatting-a-date-in-javascript) – Qantas 94 Heavy Mar 03 '15 at 05:31

1 Answers1

1

This is what is known as an Epoch Time. An easy way to retrieve the date is as follows:

var d = new Date(1425356823380);

The resulting date will be in the format you need.

Here is a JSFiddle

Stephen Rodriguez
  • 1,037
  • 1
  • 12
  • 22