I have an char arr开发者_Python百科ay of 8 bytes which contains current date in long int. How can I convert this into NSDate.
[NSDate date]
will return the current date.
alternatively, see NSDateFormatter to convert it to a string using format specification and back. beyond that... we'll need to know the internal representation of your char array.
NSDate
offers initWithTimeIntervalSinceReferenceDate
. The trick is to get the 'reference date' correct. By default, Apple uses 1 January 2001.
Jeff
If you have something like this=> 20100914
char arr[] = {'2','0','1','0','0','9','1','4','\0'};
NSString *dateString = [NSString stringWithCString:arr encoding:NSASCIIStringEncoding];
NSDateFormatter *df = [NSDateFormatter new];
[df setDateFormat:@"yyyyMMdd"];
NSDate *date = [df dateFromString:dateString];
精彩评论