可能的重复: 如何格式化JSON日期?
我的web服务返回一个DateTime到jQuery调用。该服务以以下格式返回数据:
/Date(1245398693390)/
如何将此转换为javascript友好的日期?
可能的重复: 如何格式化JSON日期?
我的web服务返回一个DateTime到jQuery调用。该服务以以下格式返回数据:
/Date(1245398693390)/
如何将此转换为javascript友好的日期?
当前回答
使用string解析日期字符串。替换为反向参考:
var milli = "/Date(1245398693390)/".replace(/\/Date\((-?\d+)\)\//, '$1');
var d = new Date(parseInt(milli));
其他回答
如果你在获取时间信息上有困难,你可以尝试这样做:
d.date = d.date.replace('/Date(', '');
d.date = d.date.replace(')/', '');
var expDate = new Date(parseInt(d.date));
你可以尝试第三方库,比如json.net,在项目网站上有文档。它说它需要。net 3.5。
还有一种叫做Nii。Json,我相信是从java的一个端口。我在这个博客上找到了一个链接
使用string解析日期字符串。替换为反向参考:
var milli = "/Date(1245398693390)/".replace(/\/Date\((-?\d+)\)\//, '$1');
var d = new Date(parseInt(milli));
如果你将DateTime从。net代码传递给javascript代码, c#:
DateTime net_datetime = DateTime.Now;
javascript将其视为字符串,如"/Date(1245398693390)/":
你可以把它转换为流动:
// convert the string to date correctly
var d = eval(net_datetime.slice(1, -1))
or:
// convert the string to date correctly
var d = eval("/Date(1245398693390)/".slice(1, -1))
http://stevenlevithan.com/assets/misc/date.format.js
var date = eval(data.Data.Entity.Slrq.replace(/\/Date\((\d )\)\//gi, "new Date($1)"));
alert(date.format("yyyy-MM-dd HH:mm:ss"));
alert(dateFormat(date, "yyyy-MM-dd HH:mm:ss"));