美文网首页
NSDate 确定时间区间

NSDate 确定时间区间

作者: 简书笔记存档 | 来源:发表于2016-07-13 15:02 被阅读0次

项目实际应用

  • (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 确定时间区间

      本文链接:https://www.haomeiwen.com/subject/vxosjttx.html