Locales can't be used in parsing dates
See original GitHub issueUpdate: This was originally a bug about missing documentation about using locales without babel.
Describe the bug I was under the assumption that locales would help in parsing dates.
I tried
const dayjs = require('dayjs');
const enGB = require('dayjs/locale/en-gb');
const dateStringUS = "09/10/2019, 08:51";
const dateStringGB = "11/09/2019, 08:50";
var dateUS = dayjs(dateStringUS).toDate();
dayjs.locale(enGB);
var dateGB = dayjs(dateStringGB).toDate();
console.log("dateUS: " + dateUS);
console.log("dateGB: " + dateGB);
and I get
dateUS: Tue Sep 10 2019 08:51:00 GMT+0200 (GMT+02:00)
dateGB: Sat Nov 09 2019 08:50:00 GMT+0100 (GMT+01:00)
Expected behavior I was expecting an output like
dateUS: Tue Sep 10 2019 08:51:00 GMT...
dateGB: Wed Sep 11 2019 08:50:00 GMT...
Using dayjs(datestring, { locale: enGB }); yielded the same result.
Information
- Day.js Version v1.8.16
- OS: Windows 10
- Browser node.js v10.15.3
- Time zone: n/a
Issue Analytics
- State:
- Created 4 years ago
- Comments:8 (3 by maintainers)
Top Results From Across the Web
apex - Date.parse not working for different locales
It works fine if the logged in user's locale is English(US) but is failing for other locales because of invalid date format. As...
Read more >GWT parse date in different locales - java - Stack Overflow
I have date from server, represented by string like "Thu Oct 31 2013 00:00:00 GMT+0200" and i have to parse it in Date...
Read more >Problem using Locale Date Format Conversions .. Need Help
I need to Internationalize my Application to Locale Settings for Dates. ... If the century cant be assumed , the 2 digit year...
Read more >4 Ways to Fix Date Errors in Power Query + Locale & Regional ...
The first way to fix a date error that stems from location differences is to choose the Using Locale setting in the Data...
Read more >Formatting / Parsing - Manual | js-joda
For example, the format eeee (d MMMM) might return Saturday (28 April) in English, and samedi (28 avril) in French. If you try...
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 Free
Top 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

Thanks, so a solution to my issue would be
Here’s working around to get the locale formats https://github.com/iamkun/dayjs/issues/680