2

I would like to use day.js to parse a date string that does not include a year. In Node.js (and Chrome, I am told), it successfully parses the string as a date but sets the year to 2001.

dayjs('06-05');    // 2001-06-06T07:00:00.000Z
dayjs('6/5');      // 2001-06-05T07:00:00.000Z
dayjs('5 June');   // 2001-06-05T07:00:00.000Z

Is there some way to detect that the original input string does not contain a year? I have considered:

  • assuming that "2001" means "no year entered" -- since my use case doesn't need the year 2001, that would be fine, but I don't want to count on that date parser always pointing to 2001.
  • manually splitting the date string. This is also problematic, since there are many delimiters and languages to consider.

Many thanks.

Graham Charles
  • 9,394
  • 3
  • 26
  • 41

0 Answers0