问题
I have a string that is (I think) an epoch date. Here is the example string:
1372620996
Heres part of the code:
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
NSDate *offerDate = [dateFormatter dateFromString:@"1372620996"];
This returns a null date, and I'm pretty sure my problem is because I haven't set a dateStyle on my NSDateFormatter. However, I'm not sure what dateStyle to use for an epoch date.
回答1:
It's actually simpler than that to convert to an NSDate;
NSString *dateStr = @"1372620996";
NSDate *date = [NSDate dateWithTimeIntervalSince1970:[dateStr doubleValue]];
NSLog(@"%@", date);
> 2013-06-30 19:36:36 +0000
来源:https://stackoverflow.com/questions/17394555/cocoa-touch-nsdateformatter-and-epoch-date