Skip to content

Locales can't be used in parsing dates #694

@raketenolli

Description

@raketenolli

Update: 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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions