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

推荐订阅源

IT之家
IT之家
aimingoo的专栏
aimingoo的专栏
H
Help Net Security
L
LangChain Blog
M
MIT News - Artificial intelligence
The GitHub Blog
The GitHub Blog
H
Hackread – Cybersecurity News, Data Breaches, AI and More
C
Check Point Blog
P
Proofpoint News Feed
J
Java Code Geeks
大猫的无限游戏
大猫的无限游戏
博客园_首页
Blog — PlanetScale
Blog — PlanetScale
U
Unit 42
I
InfoQ
月光博客
月光博客
爱范儿
爱范儿
Stack Overflow Blog
Stack Overflow Blog
V
Visual Studio Blog
Y
Y Combinator Blog
Microsoft Security Blog
Microsoft Security Blog
博客园 - Franky
D
Docker
B
Blog

博客园 - NET峰

Bind和Eval的区别详解 常用WebService一览表 信息系统集成分析师高级资格考试 利用正则表达式实现字符串搜索 玩转.net正则表达式 弹出输入框 c#.net常用函数和方法集 解决 500 Internal Server Error 搜索引擎优化(SEO) Report Server 报表服务器安装sp2补丁后,报表服务器不能用的问题解决方法 asp.net 从excel 导入时 提示:不是预期的格式错误 解决方法 javascript操作表格 示例源码 自己动手写控件----textbox之实现视图状态! 《msdn开发精选》2005年全部源代码! 创建web.config自定义配置部分 报表制作利器—Reporting Services 使用总结! 简单的XML结合XSL的例子,有助于学习内部的原理(内附源码) XMLHTTP详解 C# 格式化字符串 String.Format (推荐)
js日期格式化 - NET峰 - 博客园
NET峰 · 2010-12-13 · via 博客园 - NET峰

js日期格式化

Posted on 2010-12-13 17:12  NET峰  阅读(241)  评论()    收藏  举报

 form1.txtstime.value=stime;
       
        Date.prototype.format = function(format)
        {
                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 today = new Date();
        form1.txtendtime.value=today.format('yyyy-M-dd');