Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Create NSDate from Unix timestamp

Tags:

objective-c

How do I create an NSDate from a Unix timestamp?

channel.startDate = [NSDate dateWithTimeIntervalSince1970: (NSTimeInterval)[channelJson objectForKey:@"broadcastStartedTime"]]; 

I get this error:

104: error: pointer value used where a floating point value was expected

channels.startDate is an NSDate*. The value for the key "broadcastStartedTime" is a Javascript Number converted into an NSNumber or NSDecimalNumber by the SBJson parser library.

like image 699
JoJo Avatar asked Apr 29 '11 02:04

JoJo


1 Answers

Try this instead:

NSNumber *startTime = channelJson[@"broadcastStartedTime"]; channel.startDate = [NSDate dateWithTimeIntervalSince1970:[startTime doubleValue]]; 

Your value is trapped in a pointer type of NSNumber. The dateWithTimeIntervalSince1970 method is expecting a primitive NSTimeInterval (which, under the covers, is a double).

like image 52
Wayne Hartman Avatar answered Oct 01 '22 02:10

Wayne Hartman