1const unixTime = 1210981217;
2const date = new Date(unixTime*1000);
3console.log(date.toLocaleDateString("en-US"));
4//expected: "5/16/2008"
1var s = new Date(1504095567183).toLocaleDateString("en-US")
2// expected output "8/30/2017"
3console.log(s);
1var timestamp = 1607110465663
2var date = new Date(timestamp);
3console.log(date.getTime())
4console.log(date)
1const currentTimeInMilliseconds=Date.now(); // unix timestamp in milliseconds
1let unix_timestamp = 1549312452
2// Create a new JavaScript Date object based on the timestamp
3// multiplied by 1000 so that the argument is in milliseconds, not seconds.
4var date = new Date(unix_timestamp * 1000);
5// Hours part from the timestamp
6var hours = date.getHours();
7// Minutes part from the timestamp
8var minutes = "0" + date.getMinutes();
9// Seconds part from the timestamp
10var seconds = "0" + date.getSeconds();
11
12// Will display time in 10:30:23 format
13var formattedTime = hours + ':' + minutes.substr(-2) + ':' + seconds.substr(-2);
14
15console.log(formattedTime);
1function timeConverter(UNIX_timestamp){
2 var a = new Date(UNIX_timestamp * 1000);
3 var months = ['Jan','Feb','Mar','Apr','May','Jun','Jul','Aug','Sep','Oct','Nov','Dec'];
4 var year = a.getFullYear();
5 var month = months[a.getMonth()];
6 var date = a.getDate();
7 var hour = a.getHours();
8 var min = a.getMinutes();
9 var sec = a.getSeconds();
10 var time = date + ' ' + month + ' ' + year + ' ' + hour + ':' + min + ':' + sec ;
11 return time;
12}
13console.log(timeConverter(0));