Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 304
ahren Avatar asked Dec 15 '22 22:12

ahren


1 Answers

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(")/", ""))); 
like image 157
BlackSpy Avatar answered Jan 02 '23 07:01

BlackSpy