2

I get date in this format from web service ( oData Web Service)

/Date(847065600000)

According to this ques. How to handle json DateTime returned from WCF Data Services (OData)

This is a DateTime Object. How can I convert it to a valid iOS date format?

halfer
  • 19,824
  • 17
  • 99
  • 186
Shubhank
  • 21,721
  • 8
  • 65
  • 83

1 Answers1

4

That number is a unix timestamp i.e. the seconds passed since 1970. You can convert it to NSDate with its initializer:

  NSTimeInterval timeInterval = 847065600000;
  NSDate* date = [NSDate dateWithTimeIntervalSince1970:timeInterval];

UPDATE:

I checked your number and it seems that it is actually in milliseconds. So you should divide it by 1000 before passing to dateWithTimeIntervalSince1970: to get the correct date.

MrTJ
  • 13,064
  • 4
  • 41
  • 63
  • please tell me i'm not the only one that feels like kicking microsoft in the balls. in xml dates are returned in a human-readable format, this only happens with json – jere Aug 10 '12 at 15:53