通过Javascript或Jquery在客户端格式化JSON日期时间 [英] Format JSON Datetime on client side by Javascript or Jquery
本文介绍了通过Javascript或Jquery在客户端格式化JSON日期时间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
可能重复:
在Javascript中将日期转换为字符串
我在客户端有json格式的日期:
I have date in json format at client side :
/Date(1352745000000)/
我试图解析Json日期的代码:
The code which i have tried to parse Json date:
eval(dateTime.replace(/\/Date\((\d+)\)\//gi, "new Date($1)"));
和
new Date(parseInt(dateTime.substr(6)));
我得到的输出:
Tue Nov 27 2012 00:00:00 GMT+0530 (India Standard Time)
欲望输出
2012-11-27 11:16
我无法弄清楚我们将如何得到这个。
I am not able to figure out how we will get this.
推荐答案
var date = new Date(parseInt(dateTime.substr(6)));
var formatted = date.getFullYear() + "-" +
("0" + (date.getMonth() + 1)).slice(-2) + "-" +
("0" + date.getDate()).slice(-2) + " " + date.getHours() + ":" +
date.getMinutes();
这篇关于通过Javascript或Jquery在客户端格式化JSON日期时间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文