Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
282 views
in Technique[技术] by (71.8m points)

javascript - Parsing Date from webservice

I'm getting dates back from a webservice, and they look like this:

/Date(1310187160270+1200)/

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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
var date = new Date(1310187160270+1200); 
console.log(date)

returns

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(")/", ""))); 

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...