unix timestamp in javascript
xxxxxxxxxx
// date in milliseconds:
let ms = Date.now();
// date in seconds:
let seconds = Math.round(Date.now()/1000);
xxxxxxxxxx
const date = new Date();
const unixTimestamp = Math.floor(date.getTime() / 1000);
console.log(unixTimestamp);
xxxxxxxxxx
const unixToTime = (string) => {
const unix_timestamp = string;
const date = new Date(unix_timestamp * 1000);
const hours = date.getHours();
const minutes = "0" + date.getMinutes();
const seconds = "0" + date.getSeconds();
const newText =
hours + " : " + minutes.substr(-2) + " : " + seconds.substr(-2);
return newText
};
xxxxxxxxxx
let exp = (Math.floor(Date.now() / 1000) + 60 * 60)
console.log(exp)
const expirationDate = new Date(exp * 1000);
const formattedDate = expirationDate.toISOString();
console.log(formattedDate);