我想从用户那里收集一个日期,将其转换为 unix 纪元时间,并使用该纪元时间戳来替换我的代码中 dateWithTimeIntervalSince1970: 之后的时间戳。非常感谢任何帮助,谢谢!
-(void)updatelabel{
NSCalendar *Calender = [[NSCalendar alloc]initWithCalendarIdentifier:NSGregorianCalendar];
int units = NSDayCalendarUnit | NSHourCalendarUnit | NSMinuteCalendarUnit | NSSecondCalendarUnit;
NSDateComponents *components = [Calender components:units fromDate:[NSDate date] toDate:destinationDate options:0];
[dateLabel setText:[NSString stringWithFormat:@"%d%c %d%c %d%c %d%c", [components day], 'd', [components hour], 'h', [components minute], 'm', [components second], 's']];
}
- (void)viewDidLoad {
[super viewDidLoad];
destinationDate = [NSDate dateWithTimeIntervalSince1970:1356088260];
timer = [NSTimer scheduledTimerWithTimeInterval:1.0 target:self selector:@selector(updatelabel) userInfo:nil repeats:YES];
}