java script 日期对象Date()

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());

猜你喜欢

转载自www.cnblogs.com/stt520/p/9591765.html