question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Time format depending on the locale (bcp47)

See original GitHub issue

Hi, 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:open
  • Created 3 years ago
  • Reactions:1
  • Comments:9 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
Christian-Sandercommented, Oct 11, 2021

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.

1reaction
denyaaltcommented, Mar 24, 2021

Ok, when I have the result, I’ll post it here.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found