Skip to content

Instantly share code, notes, and snippets.

@huffmanks
Created November 1, 2023 18:36
Show Gist options
  • Save huffmanks/0543d1acfa42876109b5ddcd2764e160 to your computer and use it in GitHub Desktop.
Save huffmanks/0543d1acfa42876109b5ddcd2764e160 to your computer and use it in GitHub Desktop.
Returns a date time string that is safe to use for filenames.
/*
@title File Safe Date String
@desc Returns a date time string that is safe to use for filenames
@output 2023-11-01_14-30-39
*/
const getFileSafeDateString = () => {
const event = new Date()
const time = event.toLocaleTimeString('it-IT')
const hour = time.slice(0, 2)
const utcDate = new Date().toISOString()
const updatedDateHour = utcDate.replace(/T\d+/, `_${hour}`)
const date = updatedDateHour.replace(/:/g, '-')
return date.split('.')[0]
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment