Json日期格式转换为正常格式

来源:互联网 发布:三星荣誉勋章java 编辑:程序博客网 时间:2024/04/19 18:41
<script>
function jsonDateFormat(jsonDate){
try{
  var date=new Date(parseInt(jsonDate.replace("/Date(","").replace(")/",""),10));//json时间转换
  var month=date.getMonth()+1<10?"0"+(date.getMonth()+1):date.getMonth()+1;//月份
  var day=date.getDate()<10?"0"+date.getDate():date.getDate();//天数
  var hours=date.getHours();//时
  var minutes=date.getMinutes();//分
  var seconds=date.getSeconds();//秒
  var milliseconds=date.getMilliseconds();//毫秒
  return date.getFullYear()+"-"+month+"-"+day+""+hours+":"+minutes+":"+seconds;//返回时间
}
catch(ex){
return "对不起系统出错了!!!";//错误返回
}
}
</script>
1 0