Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>As a .NET programmer learning Objective-C I had the same problem when I tried to consume a .Net WebService.</p> <p>At first I thought I would be able to use the NSDateFormatter... I found a really good reference for it's symbols <a href="http://www.stepcase.com/blog/2008/12/02/format-string-for-the-iphone-nsdateformatter/" rel="noreferrer">here</a>, but I quickly realized that I needed to convert the number from milliseconds to seconds.</p> <p>I wrote the code to do it... I'm still learning Obj-C but I dont think It should've been this hard...</p> <pre><code>- (NSDate *) getJSONDate{ NSString* header = @"/Date("; uint headerLength = [header length]; NSString* timestampString; NSScanner* scanner = [[NSScanner alloc] initWithString:self]; [scanner setScanLocation:headerLength]; [scanner scanUpToString:@")" intoString:&amp;timestampString]; NSCharacterSet* timezoneDelimiter = [NSCharacterSet characterSetWithCharactersInString:@"+-"]; NSRange rangeOfTimezoneSymbol = [timestampString rangeOfCharacterFromSet:timezoneDelimiter]; [scanner dealloc]; if (rangeOfTimezoneSymbol.length!=0) { scanner = [[NSScanner alloc] initWithString:timestampString]; NSRange rangeOfFirstNumber; rangeOfFirstNumber.location = 0; rangeOfFirstNumber.length = rangeOfTimezoneSymbol.location; NSRange rangeOfSecondNumber; rangeOfSecondNumber.location = rangeOfTimezoneSymbol.location + 1; rangeOfSecondNumber.length = [timestampString length] - rangeOfSecondNumber.location; NSString* firstNumberString = [timestampString substringWithRange:rangeOfFirstNumber]; NSString* secondNumberString = [timestampString substringWithRange:rangeOfSecondNumber]; unsigned long long firstNumber = [firstNumberString longLongValue]; uint secondNumber = [secondNumberString intValue]; NSTimeInterval interval = firstNumber/1000; return [NSDate dateWithTimeIntervalSince1970:interval]; } unsigned long long firstNumber = [timestampString longLongValue]; NSTimeInterval interval = firstNumber/1000; return [NSDate dateWithTimeIntervalSince1970:interval]; } </code></pre> <p>Hopefully someone can provide a better Obj-C solution. If not I may keep this or look for a way to change the serialization format in .NET</p> <p>EDIT:</p> <p>About that JSON DateTime format... If you have any control on the service it would probably be best to convert the date to a string in your DataContract objects.</p> <p><a href="http://msdn.microsoft.com/en-us/library/system.globalization.datetimeformatinfo.rfc1123pattern(VS.96).aspx" rel="noreferrer">Formatting to RFC1123</a> seems like a good idea to me right now. As I can probably pick it up easily using a NSDateFormatter.</p> <p>Quote from <a href="http://www.west-wind.com/weblog/posts/324917.aspx" rel="noreferrer">Rick Strahl</a></p> <blockquote> <p>There's no JavaScript date literal and Microsoft engineered a custom date format that is essentially a marked up string. The format is a string that's encoded and contains the standard new Date(milliseconds since 1970) value.</p> </blockquote>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload