iOS 获取当天零点的时间

NSDate* now = [NSDate date];

    NSCalendar *cal = [NSCalendar currentCalendar];

    unsigned int unitFlags = NSYearCalendarUnit | NSMonthCalendarUnit | NSDayCalendarUnit | NSCalendarUnitHour | NSMinuteCalendarUnit |NSSecondCalendarUnit;

    NSDateComponents*zerocompents = [calcomponents:unitFlagsfromDate:now];

    NSLog(@"%@",zerocompents);

    // 转化成0晨0点时间

    zerocompents.hour=0;

    zerocompents.minute=0;

    zerocompents.second=0;

    NSLog(@"%@",zerocompents);

    // NSdatecomponents转NSdate类型

    NSDate*newdate= [caldateFromComponents:zerocompents];

    // //时间转毫秒的时间戳格式(该时间已经是当天凌晨零点的时刻)

    NSTimeInterval zerointerval = [newdate timeIntervalSince1970]*1000;

    longa=(long)zerointerval;

你可能感兴趣的:(iOS 获取当天零点的时间)