function formatDatebox(value) {
if (value == null || value == '') {
return '';
}
var dt = parseToDate(value); //關鍵代碼,將那個長字符串的日期值轉換成正常的JS日期格式
return dt.format("yyyy-MM-dd"); //這里用到一個javascript的Date類型的拓展方法,這個是自己添加的拓展方法,在后面的步驟3定義
}
/*帶時間*/
function formatDateBoxFull(value) {
if (value == null || value == '') {
return '';
}
var dt = parseDate(value);
return dt.format("yyyy-MM-dd hh:mm:ss");
}
var parseDate = function (timeSpan) {
var timeSpan = timeSpan.replace('Date', '').replace('(', '').replace(')', '').replace(/\//g, '');
var d = new Date(parseInt(timeSpan));
return d;
};
//為Date類型拓展一個format方法,用於格式化日期
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;
};