zoukankan      html  css  js  c++  java
  • 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());

  • 相关阅读:
    产品逻辑中的—B端技术常识:同步异步接口模式
    高德地图0907
    高德地图出异常
    svn提交报错
    高德地图demo
    JS中一些特殊的方法
    video标签的学习
    document.getElementById('file').files[0]的jquery写法
    layer请求设置遮罩
    easypoi入门<1
  • 原文地址:https://www.cnblogs.com/stt520/p/9591765.html
Copyright © 2011-2022 走看看