ITeye博客

javascript格式化json日期格式

superfofo · 2010-10-19 10:51 · javascript · Web前端 · Markdown

通过java输出json对象后的日期格式如下所示: { "date" : 19, "day" : 2, "hours" : 9, "minutes" : 24, "month" : 9, "nanos" : 0, "seconds" : 36, "time" : 1287451476000, "timezoneOffset" : -480, "year" : 110 }

纠结了很长一段时间,最后偶尔发现,可以取出对象中time的属性,然后通过以下几步进行格式化: var d = new Date(parseInt(t.time));

d的格式类似:Tue Oct 19 09:24:36 UTC+0800 2010 然后format以下d,将其输出到页面中去。

评论(1)

  1. #1 楼 · jesn89 · 2012-07-12 10:07

    function ChangeDateFormat(cellval) { var date = new Date(parseInt(cellval.replace("/Date(", "").replace(")/", ""), 10)); var month = date.getMonth() + 1 < 10 ? "0" + (date.getMonth() + 1) : date.getMonth() + 1; var currentDate = date.getDate() < 10 ? "0" + date.getDate() : date.getDate(); return date.getFullYear() + "-" + month + "-" + currentDate; };

评论功能维护中,当前仅展示历史评论。