Web API-时间对象和戳

时间对象

创建对象的过程就是实例化

//获得当前时间(小括号为空是系统当时的时间)(Date()D必须大写)
let date=new Date()
let date = new Date("2018-02-23 22:22:22");自定义时间

▲时间对象的常用方法

//创建对象
 let date = new Date();
      //获取四位年份
      console.log(date.getFullYear());
      //获得月份(取值为0-11)
      console.log(date.getMonth());
      //获取月份中的某一天
      console.log(date.getDate());
      //获取星期(取值为0-6)
      console.log(date.getDay());
      //获取小时(取值为0-23)
      console.log(date.getHours());
      //获取分钟
      console.log(date.getMinutes());
      //获取秒
      console.log(date.getSeconds());

时间戳

是指1970年01月01日00时00分00秒到现在的毫秒数

▲获得时间戳的方法

1.对象方法:getTime()
用法:let date = new Date();
console.log(date.getTime());
2.+new Date()
用法: console.log(+new Date());
console.log(+new Date());
3.Date.now()——只能获得当前时间的时间戳

★★前两种方法可以计算指定时间

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值