Skip to content

Instantly share code, notes, and snippets.

@nestoralonso
Created August 11, 2021 20:59
Show Gist options
  • Save nestoralonso/33bf3fd9bfd2a1b68dd1e06d1ae8f5cc to your computer and use it in GitHub Desktop.
Save nestoralonso/33bf3fd9bfd2a1b68dd1e06d1ae8f5cc to your computer and use it in GitHub Desktop.
formats curr date as str (useful for naming new files)
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