Posted on 2007-04-21 18:26
玄铁剑 阅读(472)
评论(0) 编辑 收藏 引用 所属分类:
Javascript
function FormatDate(strdate, marks)
{
var array_EnMonthName = ["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"];
marks = marks || "yyyy-MM-dd HH:mm:ss";
var _date = new Date(strdate);
var _returnDate = marks.replace("yyyy", _date.getFullYear());
if (_returnDate.indexOf("MMM") > -1)
_returnDate = _returnDate.replace("MMM", array_EnMonthName[_date.getMonth()]);
else
_returnDate = _returnDate.replace("MM", PutPrefix(_date.getMonth()+1, 2, "0"));
_returnDate = _returnDate.replace("dd", PutPrefix(_date.getDate(), 2, "0"));
if (_returnDate.indexOf("HH") > -1)
_returnDate = _returnDate.replace("HH", PutPrefix(_date.getHours(), 2, "0"));
if (_returnDate.indexOf("mm") > -1)
_returnDate = _returnDate.replace("mm", PutPrefix(_date.getMinutes(), 2, "0"));
if (_returnDate.indexOf("ss") > -1)
_returnDate = _returnDate.replace("ss", PutPrefix(_date.getSeconds(), 2, "0"));
return _returnDate;
}
function PutPrefix(str, len, _char)
{
var s = "";
for (var i = 0; i < len+1; i++)
s += _char;
s += str;
return s.substring(s.length-len);
}
objEndTime.innerText =FormatDate(endTime,"yyyy-MM-dd HH:mm:ss");