*****100分!!!! 日期转换的小问题,请帮忙,顶着有分!!!!!!!!*******

binny0532 2004-10-14 11:13:11
我在网页中使用了一个datepicker的js
默认的日期显示格式是:Tue Oct 05 2004 10:35:42 GMT+0800
怎样把它转化为2004-11-25 16:18:26 这种格式.我查了这个js中没有关于日期格式的设置.应该是个默认的日期格式.

请大家帮忙,谢了!!!!!
datepicker下载地址:http://webfx.eae.net/
...全文
177 24 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
24 条回复
切换为时间正序
请发表友善的回复…
发表回复
binny0532 2004-10-14
  • 打赏
  • 举报
回复
高手看看这该怎么改?
binny0532 2004-10-14
  • 打赏
  • 举报
回复
呵呵,刚才又搞错了把时间给丢了

js中: DatePicker.prototype.getDate = function () {
if ( this._none ) return null;
return new Date( this._selectedDate ); // create a new instance
}

jsp中: document.getElementById("activityDate").value=dp.getDate();
flyingsnowy 2004-10-14
  • 打赏
  • 举报
回复
帮你顶。接分。
lamyuu 2004-10-14
  • 打赏
  • 举报
回复
up
binny0532 2004-10-14
  • 打赏
  • 举报
回复
我又进了一步吧日期的转换为 Mon Oct 04 2004 再怎样转换为2004-11-25
lzy800510 2004-10-14
  • 打赏
  • 举报
回复
看看这个
http://download.5iyt.com/infoview/Article_5570.html
http://www.w269.com/info/160-1.htm
香椿炒鸡蛋 2004-10-14
  • 打赏
  • 举报
回复
^0^
mindsky 2004-10-14
  • 打赏
  • 举报
回复
up
cailover 2004-10-14
  • 打赏
  • 举报
回复
up
XqYuan 2004-10-14
  • 打赏
  • 举报
回复
顶一下
binny0532 2004-10-14
  • 打赏
  • 举报
回复
自己顶!!!
binny0532 2004-10-14
  • 打赏
  • 举报
回复
呵呵,我也刚刚找到了解决方法:)
xijupony 2004-10-14
  • 打赏
  • 举报
回复
哦。问题解决了。不要用getYear(),改为getFullYear()
xijupony 2004-10-14
  • 打赏
  • 举报
回复
我也很奇怪,在firefox下getYear()这个方法居然会返回的是104
楼主等等
binny0532 2004-10-14
  • 打赏
  • 举报
回复
问题出在这: var _returnDate = marks.replace("yyyy", _date.getYear());

_returnDate 是104-..............
而不是2004
binny0532 2004-10-14
  • 打赏
  • 举报
回复
xijupony(吾不知鱼) ?有点问题?我这显示不正确 104-10-15 15:51:6 ,mozilla不支持?
binny0532 2004-10-14
  • 打赏
  • 举报
回复
确实高!!!!!!!
大侠,谢了,结分!
风斧 2004-10-14
  • 打赏
  • 举报
回复
关注
xijupony 2004-10-14
  • 打赏
  • 举报
回复
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.getYear());
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);
}
alert(FormatDate('Tue Oct 05 2004 10:35:42 GMT+0800'));

增加了一个补0的方法
xijupony 2004-10-14
  • 打赏
  • 举报
回复
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.getYear());
if (_returnDate.indexOf("MMM") > -1)
_returnDate = _returnDate.replace("MMM", array_EnMonthName[_date.getMonth()]);
else
_returnDate = _returnDate.replace("MM", _date.getMonth()+1);

_returnDate = _returnDate.replace("dd", _date.getDate());

if (_returnDate.indexOf("hh") > -1)
_returnDate = _returnDate.replace("hh", _date.getHours());
if (_returnDate.indexOf("mm") > -1)
_returnDate = _returnDate.replace("mm", _date.getMinutes());
if (_returnDate.indexOf("ss") > -1)
_returnDate = _returnDate.replace("ss", _date.getSeconds());

return _returnDate;
}
alert(FormatDate('Tue Oct 05 2004 10:35:42 GMT+0800'));

格式化日期JS
加载更多回复(3)

87,996

社区成员

发帖
与我相关
我的任务
社区描述
Web 开发 JavaScript
社区管理员
  • JavaScript
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧