banner
lzyoo

lzyoo

本人职业:前端开发工程师 工作年限:三年 技术栈:React、Vue、Nest、Python 一直在努力,一直在放弃,好想有一个引路人带领。

Usage of dayjs custom time parsing plugin

Scenario: The form in the project uses a time picker in hours and minutes format, converting data from the interface format to form data.#

  1. Using moment's format works normally.
  2. 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,...}

Loading...
Ownership of this post data is guaranteed by blockchain and smart contracts to the creator alone.