時間日期格式化

/*日期時間格式化方法*/

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;

}

使用方法:new Date(”毫秒數(shù)“).Format("yyyy-MM-dd")

? ? ? ? ? ? ? ? new Date().Format("yyyy-MM-dd hh:mm:ss S")---2017-06-08 15:41:28 185

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容