As momentjs has the ability take into account the date format for differernt locales, does it have the ability to localize time (hour:minute) format?
According to oracle docs time format there're some time format difference across region https://docs.oracle.com/cd/E19455-01/806-0169/overview-6/index.html
moment().locale(somelocale).format('L') this will output the formatted date
However
moment().locale(somelocale).format('LT') doesn't seem like to have the same ability?
class TimeFormatter extends React.Component {
render() {
const browserLocale = window.navigator.userLanguage || window.navigator.language;
return (
<div>
{moment(this.props.value, 'HH:mm').locale(browserLocale).format('LT')}
</div>);
}
}
Above is my code for formatting the time cell on react data grid, but while I change the chrome settings the format stays the same.
So if I want to achieve time format localization can I use momentjs or I have to just come up a if else condition for setup specific user region time format
Many Thanks
The LT
format does take locale into account.
Here are some examples:
moment().locale('en-CA').format('LT') //=> "1:21 PM"
moment().locale('fr-CA').format('LT') //=> "13:21"
moment().locale('fi-FI').format('LT') //=> "13.21"
moment().locale('de-DE').format('LT') //=> "13:21"
moment().locale('no-NO').format('LT') //=> "1:21 PM"
moment().locale('th-TH').format('LT') //=> "13:21"
moment().locale('en-GB').format('LT') //=> "13:21"
Note that the Oracle page you linked to is part of the Solaris 8 documentation - an operating system which came out in February 2000 and reached end of life in March 2012. It is sorely mistaken with regard to the time formats used in those countries and languages. You should not use it as a reference.
Also note that that it made a grave error in assuming that "Canadian" was enough to identify a locale completely. As shown above, French speaking Canadians use a 24-hour clock, but many English speaking Canadians sometimes use a 12-hour clock (see Time notation in Canada) and thus en-CA
gives the 12-hour format while fr-CA
gives the 24-hour format.
Thus, country alone is not enough. A locale must consist of at least language, but usually both language and country are necessary. These are now called "IETF language tags" and are standardized by BCP 47.
As far as why Moment's German localization doesn't include the string Uhr
in the result, that was something that was first added with #1601, but then removed with #2006 - both back in 2014. See those issues for reasoning.
Also note that Moment's localization strings come from community submitted feedback and moment contributors. In many cases they align to the standards collated by Unicode CLDR, but in some cases they differ. If you are looking for a modern date library with standardized localization support, consider Luxon which leverages the internationalization APIs built into modern browsers.
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments