dayjs

方法

const time = dayjs() 
// d {$L: "en", $d: Thu Jul 08 2021 10:59:37 GMT+0800 (中国标准时间), $x: {…}, $y: 2021, $M: 6, …}
const time = dayjs().format()                    
//2021-07-08T11:00:24+08:00
const time = dayjs('2018-04-04T16:00:00.000Z')   
//d {$L: "en", $d: Thu Apr 05 2018 00:00:00 GMT+0800 (中国标准时间), $x: {…}, $y: 2018, $M: 3, …}
const time = dayjs("12-25-1995").format()        // 1995-12-25T00:00:00+08:00
const time = dayjs(1318781876406).format()       //2011-10-17T00:17:56+08:00
const time = new Date(2018, 8, 18)

// 设置今天 小时/分钟/秒/毫秒(当超出时间,会往前进一)    2021-07-08T05:40:01+08:00
const time = dayjs().hour(5).minute(39).second(61).millisecond(40).format()

// 获取当前时间  年(year)月(month)日(date) 小时(hour)分钟(minute)秒(second)毫秒(millisecond)
const time = dayjs().get('millisecond')

// ***方法***   年(year)月(month)日(day) 小时(hour)分钟(minute)秒(second)毫秒(millisecond)
// add 加     
const time = dayjs().add(7, 'year')
// subtract 减
const time = dayjs().subtract(7, 'year')
// 开始时间 startOf   结束 endOf
const time = dayjs().startOf('year').format()
const time = dayjs().endOf('year').format()

const time = dayjs().format()

// 格式化日期
const time = dayjs().format('DD/MM/YYYY') 03/4/2019

// 比对两个日期的差值 , 可以设置第二个参数看差几个月或者多少天
const date1 = dayjs('2019-01-25')
const date2 = dayjs('2018-06-05')
const as = date1.diff(date2,'month') // 20214000000 default milliseconds

const time = dayjs().valueOf()  // 获取毫秒的时间戳  1625738221175
const time = dayjs().unix()     //获取秒的时间戳     1625738259
const time = dayjs().daysInMonth() //获取当前月份的天数
const time = dayjs().toDate() //获取中国标准时间   Thu Jul 08 2021 18:01:05 GMT+0800 (中国标准时间)

// 返回日期的字符串表示形式。
const time = dayjs().toString()   //Fri, 09 Jul 2021 07:00:36 GM
// 查询当前时间是否在这个时间之前,返回bool。 可接收第二个参数
const time = dayjs().isBefore(1595519999999,'year')
// 查询当前时间是否在这个时间之后,返回bool。 可接收第二个参数
const time = dayjs().isAfter(1595519999999,'year')   
// 是否为Day.js对象。
const time = dayjs.isDayjs(dayjs()) // true
  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值