国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 語言 > JavaScript > 正文

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

2024-05-06 16:00:30
字體:
來源:轉載
供稿:網友
這篇文章主要介紹了js格式化時間和js格式化時間戳示例,需要的朋友可以參考下

復制代碼 代碼如下:


/**
 * 時間對象的格式化;
 */
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;
}

復制代碼 代碼如下:


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

復制代碼 代碼如下:


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

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表

圖片精選

主站蜘蛛池模板: 获嘉县| 拉萨市| 镇雄县| 南开区| 锡林浩特市| 山西省| 乐昌市| 玉田县| 建德市| 卓资县| 郧西县| 丹江口市| 三原县| 崇义县| 通化市| 铁岭市| 乌兰县| 光泽县| 惠东县| 福州市| 伊宁县| 榆树市| 武夷山市| 行唐县| 北票市| 巨鹿县| 乐亭县| 丹寨县| 龙川县| 西昌市| 尼木县| 江西省| 华池县| 兴业县| 区。| 历史| 新平| 平舆县| 蓬莱市| 平江县| 广汉市|