Skip to content

Instantly share code, notes, and snippets.

@autr
Created March 18, 2021 00:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save autr/546f470efca4ca1eb9ec6e723eb35023 to your computer and use it in GitHub Desktop.
Save autr/546f470efca4ca1eb9ec6e723eb35023 to your computer and use it in GitHub Desktop.
vanilla js date and time stamp strings (not bullshit, works)
// so many bullshit javascript tutorials...
const unix = 1615834045 // unix timstamp
const date = new Date( unix * 1000) // multiply
const iso = d.toISOString() // iso timestamp
// -> "2021-03-15T18:47:25.000Z"
const slug = iso.substr(0, 19).replace(/[^\w\-]+/g, '-').replace('T','-') // slug from ISO
// -> "2021-03-15-18-47-25"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment