Skip to content

Instantly share code, notes, and snippets.

@greenbicycle
Created February 21, 2019 21:56
Show Gist options
  • Save greenbicycle/908ef536f3c2309aa8c96e762a5088ba to your computer and use it in GitHub Desktop.
Save greenbicycle/908ef536f3c2309aa8c96e762a5088ba to your computer and use it in GitHub Desktop.
javascript date formatting unix timestamp
/* format a unixtimestamp as a javascript date
function formattedDate(unixTimestamp) {
let createdAtDateUTC = new Date(unixTimestamp * 1000);
let results = new Date(
createdAtDateUTC.getFullYear(),
createdAtDateUTC.getMonth(),
createdAtDateUTC.getDate(),
createdAtDateUTC.getHours(),
createdAtDateUTC.getMinutes(),
);
return results
}
console.log(formattedDate(1557900000).toLocaleDateString());
console.log(formattedDate(1557900000).toLocaleTimeString());
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment