Created
February 21, 2019 21:56
-
-
Save greenbicycle/908ef536f3c2309aa8c96e762a5088ba to your computer and use it in GitHub Desktop.
javascript date formatting unix timestamp
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* 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