Ahmed Ahmed
Ahmed Ahmed

Reputation: 1

How to load a json file based on locale of the browser in angular1.x?

In my project the selection of browser locale I want to change the date format, how can I get the date format according to the locale in javascript or angularjs

Upvotes: -1

Views: 109

Answers (1)

Pooya Estakhri
Pooya Estakhri

Reputation: 1299

in order to detect user time format you can use Moment.js.

after including moment.js library, first detect user locale by this javascript code :

let user_locale = window.navigator.userLanguage || window.navigator.language;

then feed the user_locale value to moment.locale(); function like this

moment.locale(user_locale);

after declaring localData

let localeData = moment.localeData()

you can use LongDateFormat

localeData.longDateFormat(dateFormat); // returns the full format of abbreviated date-time formats LT, L, LL and so on

to get time format.

Upvotes: 0

Related Questions