The separator between month and day is different for different locale, how can I get it?
I want to display:
"MM/DD HH:mm" for English,
"MM-DD HH:mm" for Chinese,
"MM.DD HH:mm" for German.
How can I handle it with moment.js ?
Note: I could have lots of languages, I don't want to use if the check which language is currently used, and the format must be like what I have listed above.
The solution is straight forward. There are only three possible separators /, - and ..
Simply by checking, step by step, the string containing:
let LocalDate = moment().format('l'),
LocalSeparator = (LocalDate.indexOf('/') > -1 ? "/" : (LocalDate.indexOf('-') > -1 ? '-' : '.'));
Now you can build your own date/time, using proper separator based on locale:
moment().format('YYYY[' + LocalSeparator + ']MM');
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With