首页 > 编程语言 > 详细

java script 日期对象Date()

时间:2018-09-05 14:23:08      阅读:163      评论:0      收藏:0      [点我收藏+]

java script 日期对象Date()

1.获取当前时间

  var time = new Date()

  document.write(time);  

  注意:如果Date() 有参数的话  返回1970年1月1日到指定毫秒数的时间

     当参数为 n,q,w时  n代表年 q 代表月 q代表天   其中实际月份会比参数月份+1

2.Date.now()获取当前时间戳

  document.write(Date.now())      获取当前时间距离1970年1月1日的毫秒数

  var a = new Date()

  document.write(a.getTime());     结果一样

  注意 :document.write(time); 获取的当前时间    Date.now()获取当前时间距离1970年1月1日的毫秒数

3.Date.parse()返回1970年1月1号到指定时间日期的毫秒数

  console.log(Date.parse(2015,09,26,12,23,34)); 

  参数:为年月日时分秒   Date.UTC() 国际指定日期时间到1970年1月1日。

4.获取当前的年月日时分秒分开储存

 

    console.log(d.getFullYear());
    console.log(d.getMonth()+1); //获取月份
    console.log(d.getDate()); //获取当前日
    console.log(d.getDay()); //星期几(0是星期日)
    console.log(d.getHours());
    console.log(d.getMinutes());
    console.log(d.getSeconds());
    console.log(d.getMilliseconds());
    console.log(d.getTime());

 

java script 日期对象Date()

原文:https://www.cnblogs.com/stt520/p/9591765.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!