zoukankan      html  css  js  c++  java
  • JS 中 原生方法 (三) --- Date 日期

    本文也说主要阐释了 Javascript 中的基础类型和 引用类型的自带方法,那么熟悉的同学又可以绕道了

    总是绕道,真是羞耻悳boy
    当然 本文阐述的主要类容 from MDN ( zh-cn )

    Date 日期(原生方法)

    
    var date = new Date()
    
    console.log(date)   // 返回当日的日期 和 时间
    
    /**
     * 
     * getDate()
     * 返回一个月中的某一天 ( 1-31)
     */
    
    console.log(date.getDate())     // 23
    
    
    /**
     * 
     * getDay()
     * 返回一周中的某一天 (0-6)
     */
    
    console.log(date.getDay())      // 4   (0 即为 周天)
    
    
    /**
     * 
     * getMonth()
     * 从 Date 对象中返回月份 (0-11)
     */
    
    console.log(date.getMonth())    // 1
    
    
    /**
     * 
     * getFullYear()
     * 从 date 对象中返回 四位数的年份 (1970 - xxxx)
     */
    
    console.log(date.getFullYear())     // 2017
    
    
    /**
     * 
     * getHours()
     * 返回 date 对象的 小时 (0-23)
     */
    
    console.log(date.getHours())        // 23
    
    
    /**
     * 
     * getMinutes()
     * 返回 date 对象的 分钟 (0-59)
     */
    
    console.log(date.getMinutes())      // 40
    
    
    /**
     * 
     * getSeconds()
     * 返回 date 对象的 秒数 (0-59)
     */
    
    console.log(date.getSeconds())      // 43
    
    
    /**
     * 
     * getMilliseconds()
     * 返回 date 对象的 毫秒数 (0-999)
     */
    console.log(date.getMilliseconds())  // 761
    
    
    /**
     * 
     * getTime()
     * 返回 1970-1-1 8:00 至今的 毫秒数
     */
    
    console.log(date.getTime())         // 1487864817431   约等于 47 年
    
    
    /**
     * 
     * parse()    由于是静态方法 一般 采用  Date.parse() 调用
     * 返回 从 设置的日期 到 1970-1-1 之间的 毫秒数
     */
    
    console.log(Date.parse('1991/12/23'))   // 约莫 22 年。 没毛病,笔者出生前 22年就有互联网时间啦 
    
    
    /**
     * 
     * setDate()
     * 设置 Date 对象中的 当前月的 某一天 (1-31)
     */
    date.setDate(23)
    console.log(date)     //    Wed Feb 22 2017 00:01:18 GMT+0800 (CST)
    
    /**
     * 
     * setMonth()
     * 设置 Date 对象中的 当前年的 某一月 (0-11)
     */
    date.setMonth(11)
    console.log(date)      //   Wed Nov 22 2017 00:03:25 GMT+0800 (CST)
    
    
    /**
     * 
     * setFullYear()
     * 设置 Date 对象中的 年份
     */
    
    date.setFullYear(1991)
    console.log(date)       //   Fri Nov 22 1991 00:05:15 GMT+0800 (CST)
    
    
    /**
     * 
     * setHours()
     * 设置 Date 对象中的小时 (0 ~ 23)
     */
    
    date.setHours(16)
    console.log(date)       //    Mon Dec 23 1991 16:06:59 GMT+0800 (CST)
    
    
    /**
     * 
     * setMinutes()
     * 设置 Date 对象中的分钟 (0 ~ 23)
     */
    
    date.setMinutes(16)
    console.log(date)       //    Mon Dec 23 1991 16:16:04 GMT+0800 (CST)
    
    
    /**
     * 
     * setSeconds()
     * 设置 Date 对象中的秒数 (0 ~ 59)
     */
    
    date.setSeconds(16)
    console.log(date)       //    Mon Dec 23 1991 16:16:16 GMT+0800 (CST)
    
    
    /**
     * 
     * setMilliseconds()
     * 设置 Date 对象中的毫秒数 (0 ~ 59)
     */
    
    date.setMilliseconds(16)
    console.log(date)       //    Mon Dec 23 1991 16:16:16 GMT+0800 (CST)
    
    
    /**
     * 
     * setTime()
     * 以毫秒设置 Date 对象 
     */
    
    date.setTime(1487864817431)
    console.log(date)       //    Thu Feb 23 2017 23:46:57 GMT+0800 (CST)
    
    
    /**
     * 
     * toString()
     * 把 Date 对象转换成 字符串 
     */
    
    date.toString()
    console.log(date)       //    Thu Feb 23 2017 23:46:57 GMT+0800 (CST)
    
    
    /**
     * 
     * valueOf()
     * 返回 Date 对象的原始值
     */
    
    date.valueOf()
    console.log(date)       //    Thu Feb 23 2017 23:46:57 GMT+0800 (CST)
    
    
    
  • 相关阅读:
    第二章、开发环境部署
    第一章、数据分析介绍
    爬虫之Beautiful Soup
    爬虫之selenium
    使用Python连接Mongodb,对数据库进行操作
    Python练习实例002
    Python练习实例001
    Python入门练手100例
    Python
    剑指Offer-003:从尾到头打印链表
  • 原文地址:https://www.cnblogs.com/erbingbing/p/6436215.html
Copyright © 2011-2022 走看看