您的位置:首页 > Web前端

JSON日期在前端显示的格式

2010-06-17 18:19 330 查看
Asp.Net使用Json.Net直接转化日期类型获取的日期结果为:/Date(1242357713797+0800)/

在前端页面显示需要将其格式化,可使用以下方法:

function renderTime(date) {
if (date == null || date.length !=26)
return 'null';
var da = eval('new ' + date.replace('/', '', 'g').replace('/', '', 'g'));
return da.getFullYear() + "-" + showZero(da.getMonth()) + "-" + showZero(da.getDay()) + " " + showZero(da.getHours()) + ":" + showZero(da.getMinutes()) + ":" + showZero(da.getSeconds());
}

function showZero(value) {
if (value < 12)
return "0" + value;
return value;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐