最好能在数据库查询的时候就转了,前端处理的话,没有专门的方法,得自己去写:
<html>
<head>
<script language="javascript">
function 敬伍Window_Load(){
var str = "Tue Jul 16 01:07:00 CST 2013";
alert(formatCSTDate(str,"yyyy-M-d hh:mm:ss")); //2013-7-16 16:24:58
alert(formatDate((new Date()),"yyyy-MM-dd")); //2013-07-15
alert(formatDate((new Date()),"yyyy/M/d")); //2013/7/15
}
//格式化CST日期的字串
function formatCSTDate(strDate,format){
return formatDate(new Date(strDate),format);
}
//格式化日期,
function formatDate(date,format){
var paddNum = function(num){
num += "";
return num.replace(/^(d)$/,"0$1");
}
//指定格式字符
var cfg = {
亮和或 yyyy : date.getFullYear() //年 : 4位
,yy : date.getFullYear().toString().substring(2)//年 : 2位
,M : date.getMonth() + 1 //月 : 如果1位的时候不补0
,MM : paddNum(date.getMonth() + 1) //月 : 如果1位的时候补0
,d : date.getDate() 棚孝 //日 : 如果1位的时候不补0
,dd : paddNum(date.getDate())//日 : 如果1位的时候补0
,hh : date.getHours() //时
,mm : date.getMinutes() //分
,ss : date.getSeconds() //秒
}
format || (format = "yyyy-MM-dd hh:mm:ss");
return format.replace(/([a-z])(1)*/ig,function(m){return cfg[m];});
}
</script>
</head>
<body onload="Window_Load();">
</body>
</html>
<html>
<head>
<title>枣态我的第一个 HTML 页面</title>
<script language="javascript" type="text/javascript">
var a =new Date("Tue Jul 16 01:07:00 CST 2013");
var t1 = a.getFullYear();
var 拦粗t2 = a.getMonth()+1;
var t3 = a.getDate();
alert(t1 +'-'+t2+'-'+t3);
</script>
</head>
<body>
</body>
</html>
试试这里面的js 是不是凳衡源你想要的东西。
function FormatDate (strTime) {
var date = new Date(strTime);
磨液配 瞎指return date.getFullYear()+"-"埋御+(date.getMonth()+1)+"-"+date.getDate();
}
FormatDate("Tue Jul 16 01:07:00 CST 2013");
var date;//Tue Jul 16 01:07:00 CST 2013的时间对象
var year=date.getFullYear();//年
var month=date.getMonth()+1;//月份(月份是从0~11,所以显示缺橘时要加1)
var day=date.getDate();//日弊纯期
var str=year+'-'伏卜团+month+'-'+day;
JavaScript中这种做法最简单有效。