Skip to content

Instantly share code, notes, and snippets.

@havenchyk
Last active May 22, 2020 10:08
Show Gist options
  • Save havenchyk/78129db5e977b4b36207d044eef53dda to your computer and use it in GitHub Desktop.
Save havenchyk/78129db5e977b4b36207d044eef53dda to your computer and use it in GitHub Desktop.
Format date into US format with `-` instead of `/`: mm-dd-yyyy
const now = new Date();
const options = {
timeZone: 'UTC',
day: '2-digit',
month: '2-digit',
year: 'numeric'
};
const formatter = new Intl.DateTimeFormat("en-US", options);
// mm-dd-yyyy with no library
formatter
.formatToParts(now)
.map(({ type, value }) => {
if (type === "literal") return "-";
return value;
})
.join('')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment