Last active
May 22, 2020 10:08
-
-
Save havenchyk/78129db5e977b4b36207d044eef53dda to your computer and use it in GitHub Desktop.
Format date into US format with `-` instead of `/`: mm-dd-yyyy
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
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