I tried to display date in LAO PDR ພາສາລາວ format but not works.
According to text
my code is
console.log(new Date().toLocaleString("de")); //4.6.2024, 23:26:55 this de (German is correct)
console.log(new Date().toLocaleString("lo")); //expect 4/6/2024, 23:26:55 but it shows //6/4/2024, 11:26:55 PM which is not correct
I also tried full tag "lo-LA" and by LICD "1108" from LAO PDR
What’s wrong with my code?
Thanks in advance everyone
3
Answers
I didn’t quite understand what exactly you need but based on the code you provided, and the reference to the respective library, my guess is that you don’t need any third-party modules since JavaScript itself has provided us with the "Internationalization API" internally, accessing with Intl Class:
try this code:
Keep in mind, that you can also use
timeZone: 'UTC',
option in the options object (second argument) to change the time zone, try for yourself.The output will be something like 4/6/2024, 20:36:26
According to MDN, not all localisations are supported. In your example, this might be a case of Lao not being included in the supported locales therefore, defaulting to the system’s locale (which may not be what you want.)
You are able to provide a fallback when the requested locale is not supported.
In the example above, I provided Indonesian as a fallback as it is similar to Lao’s date format. You could also use British (en-GB) fallback.
Technically, instead of using .toLocaleString() you should use .toLocaleDateString() for dates, which yields…
And my output now becomes…
Which is the reverse of what you expected, but then again maybe the fact that my operating system’s locale is different to yours may make a difference.
But anyway, I then use options to see if I can change it…
But it doesn’t seem to put them in that order! 🙁
So I turn to the Wiki article… "List of date formats by country"
https://en.wikipedia.org/wiki/List_of_date_formats_by_country
But there’s no info for Laos, so we’re stuck! 🙁