Created
December 15, 2020 23:38
-
-
Save ccnokes/187525dcf3a727abb71216469a6a3224 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 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