js将long日期格式转换为标准日期格式 复制代码 代码如下: <BR>//扩展Date的format方法 <BR>Date.prototype.format = function (format) { <BR>var o = { <BR>"M+": this.getMonth() + 1, <BR>"d+": this.getDate(), <BR>"h+": this.getHours(), <BR>"m+": this.getMinutes(), <BR>"s+": this.getSeconds(), <BR>"q+": Math.floor((this.getMonth() + 3) / 3), <BR>"S": this.getMilliseconds() <BR>} <BR>if (/(y+)/.test(format)) { <BR>format = format.replace(RegExp.$1, (this.getFullYear() + "").substr(4 - RegExp.$1.length)); <BR>} <BR>for (var k in o) { <BR>if (new RegExp("(" + k + ")").test(format)) { <BR>format = format.replace(RegExp.$1, RegExp.$1.length == 1 ? o[k] : ("00" + o[k]).substr(("" + o[k]).length)); <BR>} <BR>} <BR>return format; <BR>} <BR>/** <BR>*转换日期对象为日期字符串 <BR>* @param date 日期对象 <BR>* @param isFull 是否为完整的日期数据, <BR>* 为true时, 格式如"2000-03-05 01:05:04" <BR>* 为false时, 格式如 "2000-03-05" <BR>* @return 符合要求的日期字符串 <BR>*/ <BR>function getSmpFormatDate(date, isFull) { <BR>var pattern = ""; <BR>if (isFull == true || isFull == undefined) { <BR>pattern = "yyyy-MM-dd hh:mm:ss"; <BR>} else { <BR>pattern = "yyyy-MM-dd"; <BR>} <BR>return getFormatDate(date, pattern); <BR>} <BR>/** <BR>*转换当前日期对象为日期字符串 <BR>* @param date 日期对象 <BR>* @param isFull 是否为完整的日期数据, <BR>* 为true时, 格式如"2000-03-05 01:05:04" <BR>* 为false时, 格式如 "2000-03-05" <BR>* @return 符合要求的日期字符串 <BR>*/ <BR>function getSmpFormatNowDate(isFull) { <BR>return getSmpFormatDate(new Date(), isFull); <BR>} <BR>/** <BR>*转换long值为日期字符串 <BR>* @param l long值 <BR>* @param isFull 是否为完整的日期数据, <BR>* 为true时, 格式如"2000-03-05 01:05:04" <BR>* 为false时, 格式如 "2000-03-05" <BR>* @return 符合要求的日期字符串 <BR>*/ <BR>function getSmpFormatDateByLong(l, isFull) { <BR>return getSmpFormatDate(new Date(l), isFull); <BR>} <BR>/** <BR>*转换long值为日期字符串 <BR>* @param l long值 <BR>* @param pattern 格式字符串,例如:yyyy-MM-dd hh:mm:ss <BR>* @return 符合要求的日期字符串 <BR>*/ <BR>function getFormatDateByLong(l, pattern) { <BR>return getFormatDate(new Date(l), pattern); <BR>} <BR>/** <BR>*转换日期对象为日期字符串 <BR>* @param l long值 <BR>* @param pattern 格式字符串,例如:yyyy-MM-dd hh:mm:ss <BR>* @return 符合要求的日期字符串 <BR>*/ <BR>function getFormatDate(date, pattern) { <BR>if (date == undefined) { <BR>date = new Date(); <BR>} <BR>if (pattern == undefined) { <BR>pattern = "yyyy-MM-dd hh:mm:ss"; <BR>} <BR>return date.format(pattern); <BR>} <BR>//alert(getSmpFormatDate(new Date(1279849429000), true)); <BR>//alert(getSmpFormatDate(new Date(1279849429000),false)); <BR>//alert(getSmpFormatDateByLong(1279829423000, true)); <BR>alert(getSmpFormatDateByLong(1279829423000,false)); <BR>//alert(getFormatDateByLong(1279829423000, "yyyy-MM")); <BR>//alert(getFormatDate(new Date(1279829423000), "yy-MM")); <BR>//alert(getFormatDateByLong(1279849429000, "yyyy-MM hh:mm")); <BR>