Skip to content

Instantly share code, notes, and snippets.

@jasp402
Last active June 8, 2018 15:44
Show Gist options
  • Save jasp402/0a68a132d180e20dc7de40d473f8b25c to your computer and use it in GitHub Desktop.
Save jasp402/0a68a132d180e20dc7de40d473f8b25c to your computer and use it in GitHub Desktop.
JavaScript - FormatDate Time
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