Time format depending on the locale (bcp47)
See original GitHub issueHi, How to display time in locale specific format (bcp47 language tag)?
const event=new Date();
const options={timeZone:'UTC',year:'numeric',month:'numeric',day:'numeric',hour:'numeric',minute:'numeric',second:'numeric'};
console.log(event.toLocaleDateString('ko-KR', options)); // → "2021. 3. 20. 오후 3:40:17"
console.log(event.toLocaleDateString('en-GB', options)); // → "20/03/2021, 15:40:17"
console.log(event.toLocaleDateString('en-US', options)); // → "3/20/2021, 3:40:17 PM"
console.log(event.toLocaleDateString('de-DE', options)); // → "20.3.2021, 15:40:17"
console.log(event.toLocaleDateString('ru-RU', options)); // → "20.03.2021, 15:40:17"
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/toLocaleDateString
Thanks.
Issue Analytics
- State:
- Created 3 years ago
- Reactions:1
- Comments:9 (4 by maintainers)
Top Results From Across the Web
Unicode Locale Data Markup Language (LDML)
Unicode LDML uses stable identifiers based on [BCP47] for distinguishing among languages, locales, regions, currencies, time zones, transforms, and so on.
Read more >JavaScript Intl/BCP 47: How to use ISO date format `yyyy-mm ...
Use en-CA as locale. Afaik there is no specific locale to format into the 'modern' (iso) date string. Either split and reorder the...
Read more >Language Tags and Locale Identifiers for the World Wide Web
It describes how language tags are used to indicate a user's locale preferences which, in turn, are used to process, format, and display ......
Read more >RFC 6497 - BCP 47 Extension T - Transformed Content
BCP 47 Extension T - Transformed Content (RFC 6497, February 2012) ... Last updated, 2022-10-25. RFC stream, Internet Engineering Task Force (IETF). Formats....
Read more >IETF language tag - Wikipedia
An IETF BCP 47 language tag is a standardized code or tag that is used to identify human ... it does not provide...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I think this might be more or less what you’re looking for, please correct me if you mean something else. https://jsfiddle.net/8axt0odu/
It would require to exchange the formatting function (fmtDate?) with Intl.DateTimeFormat().format() and add new lines and colons where needed manually. I think this should not be a problem because these are inserted at defined places?
Also it would be good if it was possible to switch between automatic locale and manually set locale so the user can switch the language if needed.
Ok, when I have the result, I’ll post it here.