zoukankan      html  css  js  c++  java
  • javascript获取当前日期和时间

    function GetDate(format) {
    /**
    * format=1表示获取年月日
    * format=0表示获取年月日时分秒
    * **/
    var now = new Date();
    var year = now.getFullYear();
    var month = now.getMonth()+1;
    var date = now.getDate();
    var day = now.getDay();//得到周几
    var hour = now.getHours();//得到小时
    var minu = now.getMinutes();//得到分钟
    var sec = now.getSeconds();//得到秒
    if (format==1){
    _time = year+"-"+month+"-"+date
    }
    else if (format==2){
    _time = year+"-"+month+"-"+date+" "+hour+":"+minu+":"+sec
    }
    return _time
    }

    alert("当前日期为: " + GetDate(
    0));
  • 相关阅读:
    3.12
    3.11
    安卓开发
    安卓开发
    安卓开发
    安卓开发
    安卓开发
    安卓开发
    安卓开发
    安卓开发
  • 原文地址:https://www.cnblogs.com/fanjp666888/p/10370684.html
Copyright © 2011-2022 走看看