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

js格式化時間和js格式化時間戳示例

 更新時間:2014年02月10日 10:03:24   作者:  
這篇文章主要介紹了js格式化時間和js格式化時間戳示例,需要的朋友可以參考下

復(fù)制代碼 代碼如下:

/**
 * 時間對象的格式化;
 */
Date.prototype.format = function(format) {
    /*
     * eg:format="YYYY-MM-dd hh:mm:ss";
     */
    var o = {
        "M+" :this.getMonth() + 1, // month
        "d+" :this.getDate(), // day
        "h+" :this.getHours(), // hour
        "m+" :this.getMinutes(), // minute
        "s+" :this.getSeconds(), // second
        "q+" :Math.floor((this.getMonth() + 3) / 3), // quarter
        "S" :this.getMilliseconds()
    // millisecond
    }

    if (/(y+)/.test(format)) {
        format = format.replace(RegExp.$1, (this.getFullYear() + "")
                .substr(4 - RegExp.$1.length));
    }

    for ( var k in o) {
        if (new RegExp("(" + k + ")").test(format)) {
            format = format.replace(RegExp.$1, RegExp.$1.length == 1 ? o[k]
                    : ("00" + o[k]).substr(("" + o[k]).length));
        }
    }
    return format;
}

復(fù)制代碼 代碼如下:

var   now = new Date().format("yyyy-MM-dd hh:mm:ss");

復(fù)制代碼 代碼如下:

new Date().format("yy-MM-dd hh:mm");

相關(guān)文章

最新評論