IOS 零点时间

NSDate* now = [NSDate date];
NSCalendar *cal = [NSCalendar currentCalendar];
unsigned int unitFlags = NSYearCalendarUnit | NSMonthCalendarUnit | NSDayCalendarUnit | NSCalendarUnitHour | NSMinuteCalendarUnit |NSSecondCalendarUnit;
NSDateComponents *zerocompents = [cal components:unitFlags fromDate:now];
NSLog(@"%@",zerocompents);
// 转化成0晨0点时间
zerocompents.hour=0;
zerocompents.minute=0;
zerocompents.second=0;
NSLog(@"%@",zerocompents);
// NSdatecomponents转NSdate类型
NSDate *newdate= [cal dateFromComponents:zerocompents];
// //时间转毫秒的时间戳格式(该时间已经是当天凌晨零点的时刻)
NSTimeInterval zerointerval = [newdate timeIntervalSince1970];
long a=(long)zerointerval;

你可能感兴趣的:(IOS 零点时间)