• JavaScript格式化日期输出


     JavaScript Code 
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
     
    <script>
        window.onload = function(){  
            Date.
    prototype.Format = function (fmt) {                    
            
    var o = {
                    
    "M+"this.getMonth() + 1,                      //月份 
                    "d+"this.getDate(),                           //日 
                    "H+"this.getHours(),                          //小时 
                    "m+"this.getMinutes(),                        //分 
                    "s+"this.getSeconds(),                        //秒 
                    "q+": Math.floor((this.getMonth() + 3) / 3),    //季度 
                    "S"this.getMilliseconds()                     //毫秒 
            };
            
    if (/(y+)/.test(fmt)) 
                fmt = fmt.replace(RegExp.$1, (
    this.getFullYear() + "").substr(4 - RegExp.$1.length));
            
    for (var k in o)
            
    if (new RegExp("(" + k + ")").test(fmt)) 
                fmt = fmt.replace(RegExp.$1, (RegExp.$1.length == 
    1) ? (o[k]) : (("00" + o[k]).substr(("" + o[k]).length)));
            
    return fmt;
            }
        
            
    var currenttime1 = new Date().Format("yyyy-MM-ddTHH:mm:ss");  
            
    var pselstart = document.getElementById("starttime");  
            pselstart.value = currenttime1;
            
    var currenttime2 = new Date().Format("yyyy-MM-ddTHH:mm:ss");  
            
    var pselend = document.getElementById("endtime");  
            pselend.value = currenttime2;   
        }
    </script>

  • 相关阅读:
    P5858
    P1171
    树莓派显示CPU温度
    Docker容器文件系统位置
    Python返回列表中距离最小的点
    【实用】ubuntu和python快速换源
    shell下实现echo彩色输出
    mysql查询主表有数据,副表0条数据的列表
    swagger加请求头带token
    Error running $classname: Command line is too long. Shorten command line for $classname
  • 原文地址:https://www.cnblogs.com/MakeView660/p/7410215.html
Copyright © 2020-2023  润新知