从网络服务解析日期 [英] Parsing Date from webservice
本文介绍了从网络服务解析日期的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我从网络服务获取日期,它们看起来像这样:
I'm getting dates back from a webservice, and they look like this:
/日期(1310187160270+1200)/
我将如何在 javascript 中将其转换为日期对象?
How would I go about converting this to a date object in javascript?
我在谷歌上搜索了一下,找不到合适的答案 - 这可能部分是因为我不确定这种类型的日期对象被称为什么 - 所以如果有人可以阐明这一点另外,那将不胜感激.
I've googled around a bit and cannot find a decent answer - this may be in part due to the fact that I'm not exactly sure what this type of date object is called - so if someone could shed light on that also, that would be appreciated.
推荐答案
var date = new Date(1310187160270+1200);
console.log(date)
返回
2011 年 7 月 9 日星期六 06:52:41 GMT+0200(南非标准时间)
Sat Jul 09 2011 06:52:41 GMT+0200 (South Africa Standard Time)
如果您需要按问题中的原样剥离它:
If you need to strip it as is in Question:
var returnVariable = "/Date(1346713200000+0100)/";
var d = new Date(parseFloat(returnVariable.replace("/Date(", "").replace(")/", "")));
这篇关于从网络服务解析日期的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文