zoukankan      html  css  js  c++  java
  • js Date对象的使用

    获取当前时间 ,用

    var now = new Date(); //获取当前时间,Tue Feb 07 2017 17:28:35 GMT+0800 (中国标准时间)

    now.getFullYear(); //2017,年份

    now.getMonth(); //1,月份的范围是0-11,1是表示2月份

    now.getDate(); //07,日

    now.getDay(); //2,星期二

    now.getHours(); //17,小时,24小时制

    now.getMinutes(); //28,分钟

    now.getSeconds(); //35,秒

    now.getMilliseconds(); //774,毫秒

    now.getTime(); //1486459715774,获取时间戳

    情人节想和女票出去吃一顿。。。。。

    var now = new Date();
    var time = now.getTime();
    var year = now.getFullYear();
    var month = now.getMonth();
    var date = now.getDate();
    var day = now.getDay();
    var hours = now.getHours();
    var minutes = now.getMinutes();
    var seconds = now.getSeconds();
    var milliseconds = now.getMilliseconds();
    if (month===1&&date===14) { //情人节是几月几号来着...
        alert('小妞,出来吧,我在餐厅定了位!');
    }else {
        alert('每天都是情人节,我们就在家吃吧!');
    }


    我们也可以创建一个指定日期时间的对象

    var date = new Date(2017,1,07,17,28,35,774);//对应 年、月(二月)、日、小时、分、秒、微秒

  • 相关阅读:
    Maven导入com.google.common.collect jar包
    poj 2192 Zipper
    poj 3278 Catch That Cow
    poj 2488 A Knight's Journey
    poj 3982 序列
    poj 2109 Power of Cryptography
    poj 3258 3273
    java中大数的一些基本运算
    hdu 1715 大菲波数
    最小生成树模板
  • 原文地址:https://www.cnblogs.com/wuhaidong-me/p/6375267.html
Copyright © 2011-2022 走看看