Skip to content

Instantly share code, notes, and snippets.

@digitalbias
Created January 29, 2020 21:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save digitalbias/fc13d7ff240b4acf3c1c66bbf19404bf to your computer and use it in GitHub Desktop.
Save digitalbias/fc13d7ff240b4acf3c1c66bbf19404bf to your computer and use it in GitHub Desktop.
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());
@digitalbias
Copy link
Author

console output from https://www.typescriptlang.org/play/

translated date is:  2020-01-29
month is  0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment