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

  • 相关阅读:
    java File获取字节流
    mybatis返回自增主键问题踩坑
    电脑右键没有新建选项解决
    mysql 索引
    高并发-原子性-AtomicInteger
    Cannot find the declaration of element 'ehcache'.
    CSRF拦截
    java责任链模式
    java实现一个简单的计数器
    Java并发编程
  • 原文地址:https://www.cnblogs.com/stt520/p/9591765.html
Copyright © 2011-2022 走看看