Created
March 18, 2021 00:28
-
-
Save autr/546f470efca4ca1eb9ec6e723eb35023 to your computer and use it in GitHub Desktop.
vanilla js date and time stamp strings (not bullshit, works)
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
// 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