Last active
June 8, 2018 15:44
-
-
Save jasp402/0a68a132d180e20dc7de40d473f8b25c to your computer and use it in GitHub Desktop.
JavaScript - FormatDate Time
This file contains 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
const FormatDateTime=str=>{ | |
let date = new Date(new Number(str)); | |
return (date instanceof Date && !isNaN(date)) ? { | |
year:date.getFullYear(), | |
month:(date.getMonth() + 1), | |
day:date.getDate(), | |
hour:date.getHours(), | |
minute:date.getMinutes(), | |
second:date.getSeconds(), | |
mlSecond:date.getMilliseconds() | |
}: date.toString() } | |
//Example! | |
console.log(FormatDateTime(1528461565988)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment