這篇文章主要介紹了javascript實現時間格式輸出FormatDate函數,可實現fmt標簽一樣對日期時間型內容格式輸入的功能,是非常實用的技巧,需要的朋友可以參考下
			本文實例講述了javascript實現時間格式輸出FormatDate函數。分享給大家供大家參考。具體如下:
			javascript沒有提供像fmt標簽一樣對日期時間型內容格式輸入的函數:
		下面是我下的時間輸出函數,使用時直接放到標簽內,調用。代碼如下
			復制代碼代碼如下:
			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;  
		}
			 
			使用時直接用
			復制代碼代碼如下:
			new Date( 時間變量 ).Format("yyyy-MM-dd HH:mm:ss")
	 			 
			希望本文所述對大家的javascript程序設計有所幫助。