Scenario: The form in the project uses a time picker in hours and minutes format, converting data from the interface format to form data.#
- Using moment's format works normally.
- Using dayjs's format results in NaN after conversion, causing an error when setFieldsValue is called.
After reading the official documentation, I found that there is an official plugin for extending dayjs's format with custom time formats.#
Plugin name: CustomParseFormat
import dayjs from 'dayjs'
import customParseFormat from 'dayjs/plugin/customParseFormat'
// Usage
dayjs('12:21', 'HH:mm') // Without the plugin M2{$H:NaN,$m:NaN,...}
dayjs.extend(customParseFormat)
dayjs('12:21', 'HH:mm') // With the plugin M2{$H:12,$m:21,...}