date from timestamp js code example
Example 1: js timestamp
var timestamp = new Date().getTime();
Example 2: unix time to date javascript
const unixTime = 1210981217;
const date = new Date(unixTime*1000);
console.log(date.toLocaleDateString("en-US"));
Example 3: how to format unix timestamp javascript
var s = new Date(1504095567183).toLocaleDateString("en-US")
console.log(s);
Example 4: javascript get timestamp
var currentTimeInSeconds=Math.floor(Date.now()/1000);
var currentTimeInMilliseconds=Date.now();
Example 5: how to get the timestamp in javascript
const currentTimeInSeconds=Math.floor(Date.now()/1000);
Example 6: javascript timestamp to date
function timeConverter(UNIX_timestamp){
var a = new Date(UNIX_timestamp * 1000);
var months = ['Jan','Feb','Mar','Apr','May','Jun','Jul','Aug','Sep','Oct','Nov','Dec'];
var year = a.getFullYear();
var month = months[a.getMonth()];
var date = a.getDate();
var hour = a.getHours();
var min = a.getMinutes();
var sec = a.getSeconds();
var time = date + ' ' + month + ' ' + year + ' ' + hour + ':' + min + ':' + sec ;
return time;
}
console.log(timeConverter(0));