jquery日期格式化的方法是什么?
答案:3 悬赏:0
解决时间 2021-10-18 18:44
- 提问者网友:世勋超人
- 2021-10-18 01:40
jquery日期格式化的方法是什么?
最佳答案
- 二级知识专家网友:枭雄戏美人
- 2021-10-18 02:52
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 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;
};
全部回答
- 1楼网友:轻雾山林
- 2021-10-18 04:59
js 字符串类型转换成时间类型:
一般是根据空格( ),冒号(:)分割字符串,然后
var dd=new Date("1998","11","29","10","11","44");
如果是上面的格式,直接转化即可: var dd=new Date("Tue, 09 Nov 2010 14:56:53 GMT");
- 2楼网友:青灯有味
- 2021-10-18 03:54
这个和 jQuery 木有关系。
直接用 javascript 截取字符串:
var str = '12/2/2013';
var arr = str.split('/');
var newStr = arr[2] + (arr[0].length > 1 ? '' : '0') + arr[0] + (arr[1].length > 1 ? '' : '0') + arr[1]
newStr 就是你要的结果
我要举报
如以上问答内容为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
大家都在看
推荐资讯