skip to Main Content

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


  1. 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:

    console.log(
        Intl.DateTimeFormat('lo-LA', {
            hour: '2-digit',
            minute: 'numeric',
            second: '2-digit',
            year: 'numeric',
            month: 'numeric',
            day: 'numeric',
        }).format(new Date()));
    

    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

    Login or Signup to reply.
  2. 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.

    console.log(new Date().toLocaleString(["lo", "id"]));

    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.

    Note, the time format might not be what you want if you go with the Indonesian fallback.

    Login or Signup to reply.
  3. Technically, instead of using .toLocaleString() you should use .toLocaleDateString() for dates, which yields…

    new Date().toLocaleDateString('lo-LA')
    

    And my output now becomes…

    2024-6-4

    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…

    let Options = {
     day: 'numeric',
     month: 'numeric',
     year: 'numeric',
    };
    
    
    alert( new Date().toLocaleDateString('lo-LA',Options) ); //expect 4/6/2024
    

    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! 🙁

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search