• 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);//对应 年、月(二月)、日、小时、分、秒、微秒

  • 相关阅读:
    勇气
    Node.js的安装和配置
    jekins构建时,远程执行shell的问题
    CDMA系统原理二
    详解Android定位
    Docker 简介
    Polly+HttpClientFactory
    K8s-Helm
    k8s-部署应用
    K8S-Pod
  • 原文地址:https://www.cnblogs.com/wuhaidong-me/p/6375267.html
Copyright © 2020-2023  润新知