Question: Why cannot instantiate with just a time (and other stuff)
- Dominant language
- JavaScript
- Stars
- 48.7k
- Forks
- 2.5k
- PR merge metrics
- No merged PRs in 30d
Description
Hi!
I'm used with `moment` to instantiate an object with just a time, like this: `moment("12:34", "HH:mm")`. This way, I will get a moment object referencing the current date with the specified hours and minutes.
While migrating code to `dayjs` I noticed this is not possible here, because I get an `Invalid Date` object. The thing is I couldn't find a reasonable explanation for this behavior, because other examples does return valid dates (see below).
```
dayjs("23:24", "HH:mm").toDate()
// Invalid Date
moment("23:24", "HH:mm").toDate()
// 2025-06-01T02:24:00.000Z
```
I also was surprised by this example, that seems totally arbitrary:
```
dayjs('12-24', 'MM-DD').toDate()
// 2001-12-24T03:00:00.000Z
moment('12-24', 'MM-DD').toDate()
// 2025-12-24T03:00:00.000Z
```
Why does dayjs default to year 2001?
Is all of this working as intended? If that's the case, it would be nice to add it to the [Differences to moment](https://day.js.org/docs/en/parse/string-format#differences-to-moment), but anyway it would probably be more reasonable to just default to the current date in every case.
Thanks!
Contributor guide
Assessment
This issue has not been assessed yet.