date函数

 

    setDate() / getDate();   从Date对象中返回一个月中的某一天(1~31)
getDay();   从Date对象返回一周中的某一天(0~6)
set / getMonth(); 从Date对象中返回月份(0~11)
set / getFullYear();   从Date对象以四位数返回年份
set / getHours(); 返回Date对象的小时(0~23)
set / getMinutes();   返回Date对象的分钟(0~59)
set / getSeconds();   返回Date对象的秒数(0~59)
set / getMilliseconds();   返回Date对象的毫秒
set / getTime();   返回1970年1月1日至今的毫秒数

var d = new Date()   //当前时间
var d = new Date("2020/11/11 10:11:12")
var d = new Date("2022-11-11 10:11:12")
var d = new Date(2019, 3, 21, 10, 11, 12)   // month: 0~11
var d = new Date(1553134272123)  

var d = new Date(2019, 2, 21, 10, 11, 12, 123) console.log(d.getDate()) // 21日 console.log(d.getMonth()) // 2(3月份) console.log(d.getFullYear()) // 2019年 console.log(d.getHours()) // 10 console.log(d.getMinutes()) // 11 console.log(d.getSeconds()) // 12 console.log(d.getMilliseconds()) // 123

console.log(d.getTime())  // 1553134272123 毫秒
console.log(d.getDay()) // 星期几, 0~6,0表示星期天

console.log(d.toDateString()) //Thu Mar 21 2019
console.log(d.toLocaleString()) //2019年3月21日 上午10:11:12
console.log(d.toLocaleDateString()) //2019年3月21日
console.log(d.toLocaleTimeString()) //上午10:11:12

 

转载于:https://www.cnblogs.com/Deaseyy/p/10859780.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值