How to convert a timestamp to a readable date / time?

I have an API result indicating a timestamp like this 1447804800000. How to convert this to readable format using javascript / jQuery?

+4
source share
2 answers

You can convert this to a readable date using the method new Date()

if you have a specific date stamp, you can get the appropriate date format using the following method

var date = new Date(timeStamp);

in your case

var date = new Date(1447804800000);

it will return

Wed Nov 18 2015 05:30:00 GMT+0530 (India Standard Time)
+6
source

Call this function and specify the 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('-');
}
;
+1
source

All Articles