-
-
Notifications
You must be signed in to change notification settings - Fork 2.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Invalid Date parsing a time without a date #1552
Comments
Tried this issue. const input = '4:30';
const format = 'h:mm';
const result = dayjs(input, format);
const result_1 = moment(input, format);
console.log(result.format('YYYY-MM-DD HH:mm:ss')); // 2021-06-29 04:30:00
console.log(result_1.format('YYYY-MM-DD HH:mm:ss')); // 2021-06-29 04:30:00 But in my case it was same result in "momentjs" and "dayjs". |
console.log("dayjs 4:43", dayjs('4:43', 'h:mm').toDate()); console.log("moment 4:43", moment('4:43', 'h:mm').toDate()); Another example/use case for parsing just the time portion to validate the time input is valid:
|
In my case. import dayjs from 'dayjs';
import customParseFormat from 'dayjs/plugin/customParseFormat';
dayjs.extend(customParseFormat); // try this.
console.log(dayjs('4:43', 'h:mm').toDate()); // 2021-06-29T19:43:00.000Z Add plugin |
That is exactly what I'm doing, except my import is |
Not import customParseFormat from "dayjs"; Should be import customParseFormat from "dayjs/plugin/customParseFormat"; Try it. |
Thanks, that fixed the time parsing, but now I am having an issue with parsing the following datetime string: |
i guess same issue. |
Something like dayjs('4:43', 'h:mm') is returning an Invalid Date. If you add in a date, e.g. dayjs('12-25-1995 4:43', 'MM-DD-YYYY h:mm'), then it works. I need to be able to parse just the time, without a date, which is what I am currently doing with momentjs. I am using Typescript/Angular, dayjs version 1.10.5. extending customParseFormat plugin, which is probably inferred from it working with the date.
The text was updated successfully, but these errors were encountered: