Search code examples
iosobjective-cnsdate

Converting an InternetDateTimeString in a NSDate


That's my code

[NSDate dateFromInternetDateTimeString:internetTime formatHint:DateFormatHintRFC3339];

In the terminal I receive this message

Could not parse RFC822 date: "1370835005000" Possible invalid format.
Could not parse RFC3339 date: "1370835005000" Possible invalid format.

Which format I must use to correctly convert this internet data time in a NSDate format?


Solution

  • Divide by 1000 to get the seconds, convert it to double and create the date:

    NSDate *date = [NSDate dateWithTimeIntervalSince1970:[internetTime doubleValue]/1000.0];