Skip to content

Instantly share code, notes, and snippets.

@droustchev
Created April 7, 2016 21:29
Show Gist options
  • Save droustchev/94b5ec8e58c65a570edd3aaa340246ed to your computer and use it in GitHub Desktop.
Save droustchev/94b5ec8e58c65a570edd3aaa340246ed to your computer and use it in GitHub Desktop.
Moment Date Length Checker
<script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.10.1/moment.js"></script>
<script>
var langs = [
'en',
'de',
'es',
'fr',
'fr-ca',
'id',
'tr',
'ru',
'zh-cn',
'zh-tw',
'pt-br',
'pt'
];
langs.forEach(function(lang) {
var shortDateFormats = {
'en': 'ddd, mmmm d',
'de': 'ddd, [der] d mmmm',
'es': 'ddd, d [de] mmmm',
'fr': 'ddd, [le] d mmmm',
'fr-ca': 'ddd, [le] d mmmm',
'id': 'ddd, mmmm d',
'tr': 'dd mmmm',
'ru': 'ddd, d mmmm',
'zh-cn': 'mmm d, ddd',
'zh-tw': 'mmm d, ddd',
'pt-br': 'ddd, d [de] mmmm',
'pt': 'ddd, d [de] mmmm'
};
var shortLanguageFormat = shortDateFormats[lang] ? shortDateFormats[lang] : shortDateFormats['en'];
moment.locale(lang, {
longDateFormat: {
'l': shortLanguageFormat,
}
});
console.log('------' + lang + '-------');
console.log(moment().format('l'));
});
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment