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.

How to get localized date?

See original GitHub issue

Hello, I’ve got a question.

Is there any way to get a date (year, month,day) in localized format without loading a locale first: require('dayjs/locale/de'), etc.?

As in: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/DateTimeFormat#using_locales

var date = new Date(Date.UTC(2012, 11, 20, 3, 0, 0));

// US English uses month-day-year order
console.log(new Intl.DateTimeFormat('en-US').format(date));
// → "12/19/2012"

// British English uses day-month-year order
console.log(new Intl.DateTimeFormat('en-GB').format(date));
// → "19/12/2012"

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:13

github_iconTop GitHub Comments

1reaction
antonisprovidakiscommented, Aug 10, 2021

No, you can load a new locale by loading a module dynamically.

Something like this: https://webpack.js.org/api/module-methods/#dynamic-expressions-in-import.

I don’t know how the final result will look like, as I haven’t implemented this myself

1reaction
antonisprovidakiscommented, Aug 10, 2021

You have to import a specific locale first:

import 'dayjs/locale/en-gb'

These are all the available locales: https://github.com/iamkun/dayjs/tree/dev/src/locale

Read more comments on GitHub >

github_iconTop Results From Across the Web

Date and time localization - Lokalise Blog
In this article, we are going to discuss some of the methods that make the date and time localization process easier.
Read more >
How do I get localized date pattern string? - java
You can use DateTimeFormatterBuilder in Java 8. Following example returns localized date only pattern e.g. "d.M.yyyy" ...
Read more >
Date.prototype.toLocaleDateString() - JavaScript | MDN
The toLocaleDateString() method returns a string with a language-sensitive representation of the date portion of the specified date in the ...
Read more >
Get Date and Time in User's locale format in JavaScript
Use the toLocaleString() method to get a date and time in the user's locale format, e.g. date.toLocaleString() .
Read more >
Java 8 Date - LocalDate, LocalDateTime, Instant - DigitalOcean
LocalDate is an immutable class that represents Date with default format of yyyy-MM-dd. We can use now() method to get the current date....
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