How to convert timestamp to readable date/time?
22,139
Solution 1
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)
Solution 2
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('-');
}
;
Solution 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
Author by
Kemat Rochi
Updated on July 09, 2022Comments
-
Kemat Rochi almost 2 years
I have an API result giving out timestamp like this
1447804800000
. How do I convert this to a readable format using Javascript/jQuery?-
Admin about 8 yearsvar x = new Date(1447804800000); Returns: Wed Nov 18 2015 11:00:00
-
Pramod Karandikar about 8 yearsPossible duplicate of How to convert milliseconds into a readable date?
-
Kunal Gadhia about 8 yearsdid you get the expected output?
-
Kemat Rochi about 8 years@KunalGadhia - Yeah now it works great. Thanks for sharing that function :)
-
Kemat Rochi about 8 years@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 about 8 yearsDo 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 ??
-
Nitheesh about 8 yearsJavascript 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.