NSDate 确定时间区间

项目实际应用

  • (BOOL)getDateForNow{
    //获取时间
    NSDate *date = [NSDate date];
    NSTimeZone *zone = [NSTimeZone systemTimeZone];

    NSInteger interval = [zone secondsFromGMTForDate: date];

    NSDate *localDate = [date dateByAddingTimeInterval: interval];

    NSCalendar *calendar = [NSCalendar currentCalendar];

    NSUInteger unitFlags = NSCalendarUnitHour|NSCalendarUnitMinute ;

    NSDateComponents *dateComponent = [calendar components:unitFlags fromDate:date];
    //当前小时
    NSInteger hour = dateComponent.hour;
    //当前分钟
    NSInteger min = dateComponent.minute;

    if (hour < 9) {
    return YES;
    }else if(hour == 9){
    if (min < 30) {
    return YES;
    }else{
    return NO;
    }
    }else if(hour == 15){
    if (min > 30) {
    return YES;
    }else{
    return NO;
    }
    }else if(hour > 15){
    return YES;
    }
    return NO;

}

你可能感兴趣的:(NSDate 确定时间区间)