Created
January 29, 2020 21:29
-
-
Save digitalbias/fc13d7ff240b4acf3c1c66bbf19404bf to your computer and use it in GitHub Desktop.
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
function zeroPad(num: number, count: number, radix: number = 10): string { | |
if (num < 0) return "-" + zeroPad(-num, count, radix); | |
const str = (num | 0).toString(radix); | |
if (str.length > count) return str; | |
return ("0".repeat(count) + str).substr(-count); | |
} | |
function formatDate(date: Date) { | |
return zeroPad(date.getFullYear(), 4) + "-" + zeroPad(date.getMonth()+1, 2) + "-" + zeroPad(date.getDate(), 2) | |
} | |
const date = "2020-01-29T08:00:00-0700" | |
const rdate = new Date(Date.parse(date)); | |
const nfilename = `${formatDate(rdate)}`; | |
console.log("translated date is: ", nfilename); | |
console.log("month is ", rdate.getMonth()); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
console output from https://www.typescriptlang.org/play/