Reputation: 5462
I have a string that its value is time. The time is formmated with "time from 1970". How can I convert this string to a nsdate object?
Upvotes: 0
Views: 750
Reputation: 1434
I did not understand what you meant by "The time is formatted with 'time from 1970'" But here is how to convert a string formatted long containing the number of seconds since 1970 to a NSDate
object:
NSDate * date = [NSDate dateWithTimeIntervalSince1970:[longValueString longLongValue]];
Sometimes the time coming from the servers are in milliseconds. In that case you need to divide it with 1000.
NSDate * date = [NSDate dateWithTimeIntervalSince1970:[longValueString longLongValue]/1000];
Upvotes: 3