欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

javascript實(shí)現(xiàn)時間格式輸出FormatDate函數(shù)

 更新時間:2015年01月13日 15:47:48   投稿:shichen2014  
這篇文章主要介紹了javascript實(shí)現(xiàn)時間格式輸出FormatDate函數(shù),可實(shí)現(xiàn)fmt標(biāo)簽一樣對日期時間型內(nèi)容格式輸入的功能,是非常實(shí)用的技巧,需要的朋友可以參考下

本文實(shí)例講述了javascript實(shí)現(xiàn)時間格式輸出FormatDate函數(shù)。分享給大家供大家參考。具體如下:

javascript沒有提供像fmt標(biāo)簽一樣對日期時間型內(nèi)容格式輸入的函數(shù):
下面是我下的時間輸出函數(shù),使用時直接放到標(biāo)簽內(nèi),調(diào)用。代碼如下

復(fù)制代碼 代碼如下:
Date.prototype.Format = function(fmt) { //author: meizz    
    if (this == "Invalid Date") { 
        return ""; 
    } 
    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; 
}

使用時直接用

復(fù)制代碼 代碼如下:
new Date( 時間變量 ).Format("yyyy-MM-dd HH:mm:ss")
 

希望本文所述對大家的javascript程序設(shè)計有所幫助。

相關(guān)文章

最新評論