Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to convert timestamp to readable date/time?

I have an API result giving out timestamp like this 1447804800000. How do I convert this to a readable format using Javascript/jQuery?

like image 712
Kemat Rochi Avatar asked Apr 04 '16 05:04

Kemat Rochi


3 Answers

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)
like image 160
Nitheesh Avatar answered Sep 19 '22 09:09

Nitheesh


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('-');
}
;
like image 20
Kunal Gadhia Avatar answered Sep 19 '22 09:09

Kunal Gadhia


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
like image 41
Arpita Avatar answered Sep 20 '22 09:09

Arpita