I have an API result giving out timestamp like this 1447804800000
. How do I convert this to a readable format using Javascript/jQuery?
Asked
Active
Viewed 2.6k times
9

Kemat Rochi
- 932
- 3
- 21
- 35
-
3var x = new Date(1447804800000); Returns: Wed Nov 18 2015 11:00:00 – Apr 04 '16 at 05:22
-
Possible duplicate of [How to convert milliseconds into a readable date?](http://stackoverflow.com/questions/8579861/how-to-convert-milliseconds-into-a-readable-date) – Pramod Karandikar Apr 04 '16 at 05:23
-
did you get the expected output? – Kunal Gadhia Apr 04 '16 at 05:27
-
@KunalGadhia - Yeah now it works great. Thanks for sharing that function :) – Kemat Rochi Apr 04 '16 at 05:32
-
@KunalGadhia - Do you also know how to do it backwards? Like, given Wed Nov 18 2015 05:30:00 GMT+0530 (India Standard Time) and covert it to 1447804800000 ?? – Kemat Rochi Apr 04 '16 at 05:40
3 Answers
15
You can convert this to a readable date using new Date()
method
if you have a specific date stamp, you can get the corresponding date time format by the following method
var date = new Date(timeStamp);
in your case
var date = new Date(1447804800000);
this will return
Wed Nov 18 2015 05:30:00 GMT+0530 (India Standard Time)

Nitheesh
- 19,238
- 3
- 22
- 49
-
Do you also know how to do it backwards? Like, given Wed Nov 18 2015 05:30:00 GMT+0530 (India Standard Time) and covert it to 1447804800000 ?? – Kemat Rochi Apr 04 '16 at 05:38
-
Javascript does not provides any inbuilt method for reverse conversion of date to date time stamp. We may need to write a custom method for this purpose. – Nitheesh Apr 04 '16 at 07:02
4
Call This function and pass your date :
JS :
function getDateFormat(date) {
var d = new Date(date),
month = '' + (d.getMonth() + 1),
day = '' + d.getDate(),
year = d.getFullYear();
if (month.length < 2)
month = '0' + month;
if (day.length < 2)
day = '0' + day;
var date = new Date();
date.toLocaleDateString();
return [day, month, year].join('-');
}
;

Kunal Gadhia
- 350
- 2
- 14
3
In my case, the REST API returned timestamp with decimal. Below code snippet example worked for me.
var ts= 1551246342.000100; // say this is the format for decimal timestamp.
var dt = new Date(ts * 1000);
alert(dt.toLocaleString()); // 2/27/2019, 12:45:42 AM this for displayed

Arpita
- 107
- 3