数码资讯
扩展js日期对象的时间格式化功能的一个小例子
用自己的js代码介绍代码: 复制代码代码如下所示: date.prototype.format =函数(格式) { var { { { { M +:this.getmonth()+ 1, / /月 D:this.getdate(), / /天 H:this.gethours(), / /小时 M +
选购提示
关注价格、性能、续航、售后和真实使用场景,理性比较后再下单。
用自己的js代码介绍代码:
复制代码代码如下所示:
date.prototype.format =函数(格式)
{
var { { { {
M +:this.getmonth()+ 1, / /月
D:this.getdate(), / /天
H:this.gethours(), / /小时
M +:this.getminutes(), / /分钟
+:this.getseconds(), / /二
Q+:Math.floor(((this.getmonth()+ 3)/ 3), / /季度
S:this.getmilliseconds() / /毫秒
};
如果((y +)测试(格式))
{
格式= format.replace(regexp。1美元,((this.getfullyear()+)。Substr(4—9。1美元。长度));
}
对于(k在O中k)
{
如果(新规则((钾))。试验(格式))
{
格式= format.replace(regexp。1美元,regexp。1美元。长度= = 1 O { }:K(00 + O { k })。Substr((+ O { k })。长度));
}
}
Return format;
};
调用的方法如下所示:
新日期();
无功nowdate = dt.format(yyyy-mm-dd HH:毫米:SS );
你可以获得当前时间:2013-12-02 14:02:11
复制代码代码如下所示:
date.prototype.format =函数(格式)
{
var { { { {
M +:this.getmonth()+ 1, / /月
D:this.getdate(), / /天
H:this.gethours(), / /小时
M +:this.getminutes(), / /分钟
+:this.getseconds(), / /二
Q+:Math.floor(((this.getmonth()+ 3)/ 3), / /季度
S:this.getmilliseconds() / /毫秒
};
如果((y +)测试(格式))
{
格式= format.replace(regexp。1美元,((this.getfullyear()+)。Substr(4—9。1美元。长度));
}
对于(k在O中k)
{
如果(新规则((钾))。试验(格式))
{
格式= format.replace(regexp。1美元,regexp。1美元。长度= = 1 O { }:K(00 + O { k })。Substr((+ O { k })。长度));
}
}
Return format;
};
调用的方法如下所示:
新日期();
无功nowdate = dt.format(yyyy-mm-dd HH:毫米:SS );
你可以获得当前时间:2013-12-02 14:02:11
声明:本文内容用于数码产品信息整理与选购参考,具体价格、库存、售后政策以官方渠道和电商页面实时信息为准。