zoukankan      html  css  js  c++  java
  • 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>

  • 相关阅读:
    安装.NET FRAMEWORK 4.5安装进度条回滚之后发生严重错误 代码0x80070643
    C#远程时间同步助手软件设计
    Win7+Ubuntu双系统安装完成后时间不一致相差大概8小时
    php中类的不定参数使用示例
    php读写xml基于DOMDocument方法
    php写的非常简单的文件浏览器
    php封装的sqlite操作类
    phpstudy中apache的默认根目录的配置
    实现基于最近邻内插和双线性内插的图像缩放C++实现
    【STL深入理解】vector
  • 原文地址:https://www.cnblogs.com/MakeView660/p/7410215.html
Copyright © 2011-2022 走看看