您好,欢迎来到三六零分类信息网!老站,搜索引擎当天收录,欢迎发信息

js 实现日期灵活格式化的小例子_javascript技巧

2024/5/30 5:31:33发布33次查看
复制代码 代码如下:
/**
 * 时间对象的格式化;
 */
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; 
}
该用户其它信息

VIP推荐

免费发布信息,免费发布B2B信息网站平台 - 三六零分类信息网 沪ICP备09012988号-2
企业名录 Product