banner
lzyoo

lzyoo

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

dayjs自定义时间解析插件使用

场景:项目里的表单使用到了时分格式的时间选择器,从接口数据 format 到表单数据。#

  1. 使用 moment 的 format 正常
  2. 使用 dayjs 的 format 导致转换后时间为 NaN,导致 setFieldsValue 时报错。

阅读官网的文档后发现有一个官方插件是用于拓展 dayjs 的 format 自定义时间格式。#

插件名:CustomParseFormat

import dayjs from 'dayjs'
import customParseFormat from 'dayjs/plugin/customParseFormat'

// 使用
dayjs('12:21', 'HH:mm') // 不使用插件 M2{$H:NaN,$m:NaN,...}

dayjs.extend(customParseFormat)
dayjs('12:21', 'HH:mm') //使用插件 M2{$H:12,$m:21,...}

加载中...
此文章数据所有权由区块链加密技术和智能合约保障仅归创作者所有。