Date计算 不用考虑跨年跨月等问题的Date计算方法 js

一些date的计算方法:

//当年第一个月的第一天
const date = new Date(new Date().getFullYear(),0)
//当前月的第一天
const date = new Date(new Date().getFullYear(),new Date().getMonth(), 1)
//当前日期加上3个月
const date = new Date(); date.setMonth(date.getMonth() + 3)
//当前日期加上3天
const date = new Date(); date.setDate(date.getDate() + 3)
//当前时间加上12小时
const date = new Date(); date.setTime(date.getTime() + 3680 * 1088 * 12);

get系列:

getDate() 返回一个月中的某一天(1-31)

getDay()    返回一周中的某一天(0-6)

getFullYear()  返回四位数的年份

getMonth()   返回月份(0-11 0是一月)

getHours()   返回的是当前的小时(0-23)

getMinutes()  返回的是当前的分钟(0-59)

getSeconds()  返回的是当前的秒(0-59)

getTime()    返回的是1970年1月1日至今的毫秒数

set系列:

parse()    返回1970年1月1日到指定日期的毫秒数

setDate()   设置一月的某一天(1-31)

setFullYear()  设置年份

setMonth()   设置月份(0-11)

setHours()    设置小时(0-23)

setMinutes()   设置分钟(0-59)

setSeconds()  设置秒数(0-59)

setTime()    以毫秒数设置Date

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值