let unix_timestamp =1549312452// Create a new JavaScript Date object based on the timestamp// multiplied by 1000 so that the argument is in milliseconds, not seconds.var date =newDate(unix_timestamp *1000);// Hours part from the timestampvar hours = date.getHours();// Minutes part from the timestampvar minutes ="0"+ date.getMinutes();// Seconds part from the timestampvar seconds ="0"+ date.getSeconds();// Will display time in 10:30:23 formatvar formattedTime = hours +':'+ minutes.substr(-2)+':'+ seconds.substr(-2);console.log(formattedTime);
let unix_timestamp =1549312452// Create a new JavaScript Date object based on the timestamp// multiplied by 1000 so that the argument is in milliseconds, not seconds.var date =newDate(unix_timestamp *1000);// Hours part from the timestampvar hours = date.getHours();// Minutes part from the timestampvar minutes ="0"+ date.getMinutes();// Seconds part from the timestampvar seconds ="0"+ date.getSeconds();// Will display time in 10:30:23 formatvar formattedTime = hours +':'+ minutes.substr(-2)+':'+ seconds.substr(-2);console.log(formattedTime);Run code snippetHide results
//Explination Toget the unix timestamp using JavaScript you need to use the getTime()functionof the build inDate object.Asthis returns the number of
milliseconds then we must divide the number by 1000 and round it in
order to get the timestamp in seconds.(newDate().getTime()/1000);// Refrence : https://www.hashbangcode.com/article/convert-date-timestamp-javascript