惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

Vercel News
Vercel News
F
Fortinet All Blogs
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
GbyAI
GbyAI
MongoDB | Blog
MongoDB | Blog
Jina AI
Jina AI
aimingoo的专栏
aimingoo的专栏
I
InfoQ
IT之家
IT之家
罗磊的独立博客
Blog — PlanetScale
Blog — PlanetScale
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
The Cloudflare Blog
爱范儿
爱范儿
Microsoft Azure Blog
Microsoft Azure Blog
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
美团技术团队
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
B
Blog RSS Feed
G
Google Developers Blog
大猫的无限游戏
大猫的无限游戏
博客园_首页
Engineering at Meta
Engineering at Meta
Martin Fowler
Martin Fowler

博客园 - harry.guo

转:Codeigniter调用PHPExcel例子 转:iphone/ipad网站开发技巧整理 转:iPhone Android Web开发(概要) 转:jquery弹出层背景变暗 - harry.guo - 博客园 转:c#播放音频文件 - harry.guo - 博客园 转载:Android模拟器的基本操作 安装android sdk 遇到几个问题 基础:JDK的概念、组成及JDK常用包(转) 基础:JDK与JRE(转) 基础:C#装箱拆箱的计算 转:对比MFC,Winform,WPF 正则在FireFox和IE下使用test的不同 - harry.guo - 博客园 知识:软件复杂度 转:如何让你的SQL运行得更快 白盒测试步骤 Ms时间处理收集 [摘]javascript的Prototype实现和OO开发- - java实现对文件的各种操作(转) - harry.guo - 博客园 实现table跳转到指定行,并改变所在行的样式!
格式化日期输出 - harry.guo - 博客园
harry.guo · 2009-05-21 · via 博客园 - harry.guo

封装方法

//格式化日期yyyy-MM-dd-mm-ss-q-S  如date.Format("yyyy/dd")
    Date.prototype.Format = function(format)
    {
        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(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 d = new Date();

var a = d.Format("yyyy年MM月dd日 hh:mm:ss")