iOS中,获取到当前的时间,减去1970年的时间差,换算成秒怎么做
1个回答
展开全部
01 //获取当前时间
02 NSDate *now = [NSDate date];
03 NSLog(@”now date is: %@”, now);
04
05 NSCalendar *calendar = [NSCalendar currentCalendar];
06 NSUInteger unitFlags = NSYearCalendarUnit | NSMonthCalendarUnit | NSDayCalendarUnit | NSHourCalendarUnit | NSMinuteCalendarUnit | NSSecondCalendarUnit;
07 NSDateComponents *dateComponent = [calendar components:unitFlags fromDate:now];
08
09 int year = [dateComponent year];
10 int month = [dateComponent month];
11 int day = [dateComponent day];
12 int hour = [dateComponent hour];
13 int minute = [dateComponent minute];
14 int second = [dateComponent second];
02 NSDate *now = [NSDate date];
03 NSLog(@”now date is: %@”, now);
04
05 NSCalendar *calendar = [NSCalendar currentCalendar];
06 NSUInteger unitFlags = NSYearCalendarUnit | NSMonthCalendarUnit | NSDayCalendarUnit | NSHourCalendarUnit | NSMinuteCalendarUnit | NSSecondCalendarUnit;
07 NSDateComponents *dateComponent = [calendar components:unitFlags fromDate:now];
08
09 int year = [dateComponent year];
10 int month = [dateComponent month];
11 int day = [dateComponent day];
12 int hour = [dateComponent hour];
13 int minute = [dateComponent minute];
14 int second = [dateComponent second];
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询