Created
November 1, 2023 18:36
-
-
Save huffmanks/0543d1acfa42876109b5ddcd2764e160 to your computer and use it in GitHub Desktop.
Returns a date time string that is safe to use for filenames.
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
/* | |
@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