Created
August 11, 2021 20:59
-
-
Save nestoralonso/33bf3fd9bfd2a1b68dd1e06d1ae8f5cc to your computer and use it in GitHub Desktop.
formats curr date as str (useful for naming new files)
This file contains hidden or 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
const formatDateAsString = date => { | |
const fmt = new Intl.NumberFormat('en-US', { | |
minimumIntegerDigits: 2, | |
useGrouping: false, | |
}); | |
const dateStr = [date.getFullYear(), date.getMonth() + 1, date.getDate()] | |
.map(fmt.format) | |
.join(''); | |
const time = [date.getHours(), date.getMinutes()] | |
.map(fmt.format) | |
.join(''); | |
return dateStr + '-' + time; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment