zoukankan      html  css  js  c++  java
  • Date内置对象

    日期对象创建
     
        时间戳是指格林威治时间1970年01月01日00时00分00秒(北京时间1970年01月01日08时00分00秒)起至现在的总毫秒数(时间戳)
     
    var date = new Date();  //当前时间的日期对象
    var data = new Date(2012,6,10);  //2012年7月10号的日期对象
     
    Date.now()    // 获取当前时间戳,得到一个number
     
     
    get系列API
    getFullYear()  返回年
    getMonth() 返回月份0--11
    getDate() 返回某一天
    getDay() 返回星期0-6
    getHours() 返回小时
    getMinutes() 返回分钟
    getSeconds() 返回秒
    getTime() 返回1970年1月1日午夜到指定日期(字符串)的毫秒数
     
    set系列API
    setFullYear() 设置年份
    setMonth() 设置月
    setDate() 设置天
    setHours() 设置小时
    setMinutes() 设置分钟
    setSeconds() 设置秒
    setTime() 使用毫秒的形式设置时间对象
     
    ★注意:
     
    1、setDay( 这个真没有!!!!,星期是通过设定日期自动计算的 )
    2、set系列API可以设置比当前范围更精细的时间
        比如:setFullYear(2012,3,5)  设置日期为2012年4月5号
                  setHours(13,30,0)  设置时间为13:30:00
    实例:
    setFullYear(year,month,day)    
     
    year:
     
    必需,表示年份的四位整数
     
    month:
     
    可选,介于 0 ~ 11 之间:如果不填,取系统当月
     
    -1 为去年的最后一个月
    12 为明年的第一个月
    13 为明年的第二个月
     
     
      date:
     
    • 可选,表示月中某一天的数值。如果不填,取系统当日
    • 用本地时间表示。介于 1 ~ 31 之间:
    • 0 为上个月最后一天
    • -1 为上个月最后一天之前的天数
    • 如果当月有31天:32 为下个月的第一天
    • 如果当月有30天:
    • 32 为下一个月的第二天

    日期的toString

     1   <script>
     2     var date = new Date()
     3     console.log(date)
     4 
     5     console.log(date.toString())
     6     console.log(date.toDateString()) // 转换为日期字符串
     7     console.log(date.toLocaleDateString()) // 转换为本地日期字符串
     8 
     9     console.log(date.toTimeString()) // 转换为时间字符串
    10     console.log(date.toLocaleTimeString()) // 转换为本地时间字符串
    11 
    12     console.log(date.toLocaleString()) // 转换为本地日期加时间完整的字符串
    13 
    14     console.log(date.toUTCString()) // 转换为标准时区的日期和时间
    15 
    16   </script>
  • 相关阅读:
    Two strings CodeForces
    Dasha and Photos CodeForces
    Largest Beautiful Number CodeForces
    Timetable CodeForces
    Financiers Game CodeForces
    AC日记——整理药名 openjudge 1.7 15
    AC日记——大小写字母互换 openjudge 1.7 14
    AC日记——将字符串中的小写字母换成大写字母 openjudge 1.7 13
    AC日记——加密的病历单 openjudge 1.7 12
    AC日记——潜伏着 openjudge 1.7 11
  • 原文地址:https://www.cnblogs.com/strongerPian/p/12716547.html
Copyright © 2011-2022 走看看