In this article, you will learn how to Convert Unix timestamp to Date time with JavaScript
<input type='text' value='1500028071' id='timestamp'>
<input type='button' id='convert' value='Convert' onclick='convert();'>
<span id='datetime'></span>
function convert(){
// Unixtimestamp
var unixtimestamp = document.getElementById('timestamp').value;
var months_arr = ['Jan','Feb','Mar','Apr','May','Jun','Jul','Aug','Sep','Oct','Nov','Dec'];
// Convert timestamp to milliseconds
var date = new Date(unixtimestamp*1000);
var year = date.getFullYear();
var month = months_arr[date.getMonth()];
var day = date.getDate();
var hours = date.getHours();
var minutes = "0" + date.getMinutes();
var seconds = "0" + date.getSeconds();
// Display date time in MM-dd-yyyy h:m:s format
var convdataTime = month+'-'+day+'-'+year+' '+hours + ':' + minutes.substr(-2) + ':' + seconds.substr(-2);
document.getElementById('datetime').innerHTML = convdataTime;
}
Convert Unix timestamp to Date time with JavaScript
minify code