html日期对象怎么设置,日期对象.html

Document

// 日期对象是内置对象

console.log(new Date()) // Tue Jun 02 2020 12:37:37 GMT+0800 (中国标准时间)

console.log(typeof (new Date())) // object

// 使用函数获取时间

console.log(Date()) // Tue Jun 02 2020 12:37:37 GMT+0800 (中国标准时间)

// 获取时间戳

console.log(Date.now()) //1591072805971

console.log((new Date()).getTime());

console.log((new Date()).valueOf());

console.log(Number(new Date())) // 直接转换为整数

// 计算执行时间

let start = Date.now();

for (let i = 0; i < 200000000; i++) { }

let end = Date.now();

console.log(`执行时间为:${end - start}`);

// 指定日期和时间对象

// 使用字符串表示时间

let now1 = '2020-05-22 12:43:12'

let now = new Date(now1);

console.log(now) // Fri May 22 2020 12:43:12 GMT+0800 (中国标准时间)

// 使用数组表示时间

let now2 = [2020, 1, 22, 12, 44]; // 月份从0-11

console.log(new Date(...now2)) // Sat Feb 22 2020 12:44:00 GMT+0800 (中国标准时间)

// 日期类库

// http://momentjs.cn/

一键复制

编辑

Web IDE

原始数据

按行查看

历史

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值