您的位置:首页 > 其它

如何获取当天凌晨的时间

2016-06-29 17:30 267 查看
查了不少资料,终于东拼西凑出来了,实属不易啊

NSTimeZone *gmt = [NSTimeZone timeZoneWithAbbreviation:@"GMT"];

NSCalendar *calendar = [[NSCalendar alloc] initWithCalendarIdentifier: NSGregorianCalendar];

[calendar setTimeZone:gmt];

NSDate *date = [NSDate date];

NSDateComponents *components = [calendar components:NSUIntegerMax fromDate:date];

components.day-=1;

[components setHour:0];

[components setMinute:0];

[components setSecond: 0];

NSDate *startDate = [calendar dateFromComponents:components];

NSDate *endDate = [calendar dateByAddingUnit:NSCalendarUnitDay value:1 toDate:startDate options:0];

NSLog(@"%@", endDate);
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: