Data对象的方法

1. 创建日期对象
eg: 当前时间:
var date1 = new Date();
console.log(date1);
eg: 指定时间:
var date2 = new Date('2000-10-2 12:00:00')
console.log(date2);
eg: 以总毫秒数指定时间(以Thu Jan 01 1970 08:00:00为时间基准线)
var date3 = new Date(5000);
console.log(date3);  // Thu Jan 01 1970 08:00:05
2. 日期对象的方法
eg: 获取年份:
console.log(date1.getFullYear());
eg: 获取月份:(注意:0(一月)~11(十二月))
console.log(date1.getMonth());
eg: 获取日期:
console.log(date1.getDate());
eg: 获取时:
console.log(date1.getHours());
eg: 获取分:
console.log(date1.getMinutes());
eg: 获取秒:
console.log(date1.getSeconds());
eg: 获取时间戳:getTime():获取某个日期时间 距离 1970年1月1日 的总毫秒数
方式一:
console.log(date1.getTime());
console.log(date1 - date2);

方式二:
var date = new Date(date1 - date2)
console.log(date.getTime());
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值