首頁  >  文章  >  web前端  >  js格式化時間和js格式化時間戳記範例_基礎知識

js格式化時間和js格式化時間戳記範例_基礎知識

WBOY
WBOY原創
2016-05-16 17:00:491180瀏覽

複製程式碼程式碼如下:

/**
 * 時間對象的格式化;
 *


/***
日期.prototype.format = function(format) {
    /*
     * 例如:format="YYY >        "M " :this.getMonth() 1, // 月
        "d " :this.getDate(), // 日
    "d " :this.getDate(), // 日
   "m " :this.getMinutes(), // 分鐘
        "s " :this.getSeconds(), // 秒
        "q " :Math.floor((this.Month 3) 33) 3 ), // 四分之一
        "S" :this.getMilliseconds()
    // 毫秒
    }

    if (/(y )/.test(format)) {
        format = format.replace(RegExp.$1, (this.getFullYear p.$1 .length));
    }

    for ( var k in o) {

        if (new RegExp("(" k ")").test(format)) {
   .length == 1 ? o[k]
                    : ("00" o[k]).substr     : ("00" o[k]).substr("" o[k]).length)).
回傳格式;
}



複製程式碼程式碼如下:var   代碼-MM-dd 時:分:秒");


複製程式碼程式碼如下:new Date().format("yyy-MM- dd hh:mm");

陳述:
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn