js时间转换

lsx521lxd 2008-10-28 02:21:06
数据库DataTime类型的时间,在页面显示的时候 显示这个 ---> Thu May 8 12:12:12 UTC+0800 2008

怎么用JavaScript转换成 2008-5-12 12:12:12 。
数据是从后台取出来的,放到ds里的,在前台js方法里
把ds赋值给var ds1。只要求在前台转换。
...全文
131 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
ldcah 2008-12-16
  • 打赏
  • 举报
回复
//格式化时间 Thu May 8 12:12:12 UTC+0800 2008 转换成 2008-5-12 12:12:12 。

function formatDateFromUTC(utcDate)
{
var date=new Date(utcDate);
var yy=date.getFullYear ();

var MM=date.getMonth ()+1;
if(MM<10)
{
MM="0"+MM;
}
var dd=date.getDate ();
if(dd<10)
{
dd="0"+dd;
}
// var hh=date.getHours ();
//
// if(hh<10)
// {
// hh="0"+hh;
// }
// var mm=date.getMinutes();
// if(mm<10)
// {
// mm="0"+mm
// }
// var ss=date.getSeconds ();//02
// if(ss<10)
// {
// ss="0"+ss;
// }
return yy+"-"+MM+"-"+dd;
}
tantaiyizu 2008-10-28
  • 打赏
  • 举报
回复
in your example,firstly, u need to use split make the UTC string to the Array;

then u can new date() to call that functions to slove ur problem.
tantaiyizu 2008-10-28
  • 打赏
  • 举报
回复
hi,i have some function about date object of javascript,u can see it to use..

setUTCDate() Sets the day of the month in a Date object according to universal time (from 1-31)

setUTCMonth() Sets the month in a Date object according to universal time (from 0-11)

setUTCFullYear() Sets the year in a Date object according to universal time (four digits)

setUTCHours() Sets the hour in a Date object according to universal time (from 0-23)

setUTCMinutes() Set the minutes in a Date object according to universal time (from 0-59)

setUTCSeconds() Set the seconds in a Date object according to universal time (from 0-59)

setUTCMilliseconds()
北极鹅 2008-10-28
  • 打赏
  • 举报
回复
貌似没有现成的JS方法,在后台处理或者自己写个JS吧。

87,910

社区成员

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

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