Skip to content

Instantly share code, notes, and snippets.

@ccnokes
Created December 15, 2020 23:38
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 ccnokes/187525dcf3a727abb71216469a6a3224 to your computer and use it in GitHub Desktop.
Save ccnokes/187525dcf3a727abb71216469a6a3224 to your computer and use it in GitHub Desktop.
function getMonths(locale: string, format: 'long' | 'short' = 'long') {
const monthNames = [];
const currentYear = new Date().getFullYear();
for (let i = 0; i < 12; i++) {
monthNames.push(
new Date(currentYear, i, 1).toLocaleDateString(locale, {
month: format
}));
}
return monthNames;
}
// getMonths('de')
// ["Januar", "Februar", "März", "April", "Mai", "Juni", "Juli", "August", "September", "Oktober", "November", "Dezember"]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment