日期转换成指定格式字符串
Date.prototype.Format = function (patten) {
if (/(yyyy)/g.test(patten)) {
patten = patten.replace(RegExp.$1, this.getFullYear());
}
else if (/(yy)/g.test(patten)) {
patten = patten.replace(RegExp.$1, this.getFullYear().toString().substr(2, 2));
}
else if (/(y)/g.test(patten)) {
patten = patten.replace(RegExp.$1, this.getFullYear());
}
if (/(MM)/g.test(patten)) {
patten = patten.replace(RegExp.$1, ('0' + (this.getMonth() + 1)).slice(-1 * 2));
}
else if (/(M)/g.test(patten)) {
patten = patten.replace(RegExp.$1, (this.getMonth() + 1));
}
if (/(dd)/g.test(patten)) {
patten = patten.replace(RegExp.$1, ('0' + this.getDate()).slice(-1 * 2));
}
else if (/(d)/g.test(patten)) {
patten = patten.replace(RegExp.$1, this.getDate());
}
if (/(HH)/g.test(patten)) {
patten = patten.replace(RegExp.$1, ('0' + this.getHours()).slice(-1 * 2));
}
else if (/(H)/g.test(patten)) {
patten = patten.replace(RegExp.$1, this.getHours());
}
if (/(mm)/g.test(patten)) {
patten = patten.replace(RegExp.$1, ('0' + this.getMinutes()).slice(-1 * 2));
}
else if (/(m)/g.test(patten)) {
patten = patten.replace(RegExp.$1, this.getMinutes());
}
if (/(ss)/g.test(patten)) {
patten = patten.replace(RegExp.$1, ('0' + this.getSeconds()).slice(-1 * 2));
}
else if (/(s)/g.test(patten)) {
patten = patten.replace(RegExp.$1, this.getSeconds());
}
if (/(f+)/g.test(patten)) {
patten = patten.replace(RegExp.$1, this.getMilliseconds());
}
return patten;
}
日期增加及减少
待完善
|