Skip to content

@pmun/utils / createDate

Function: createDate() ​

ts
function createDate(date?): Dayjs;

创建 dayjs 对象

Parameters ​

date? ​

日期参数,可以是日期对象、Dayjs 对象、时间戳(秒或毫秒,支持数字字符串)或日期字符串;省略时使用当前日期时间

DateLike | Dayjs

Returns ​

Dayjs

dayjs 对象;0、'0' 或无效日期输入返回无效的 dayjs 对象

Example ​

ts
createDate() // 当前日期时间
createDate('2023-05-15') // 指定日期
createDate(1684123456000) // 时间戳
createDate('1684123456') // 秒级字符串时间戳
createDate('0').isValid() // false
createDate(0).isValid() // false