iOS 判断时间是不是今天

作者: ios_暗夜行者 | 来源:发表于2021-05-31 15:43 被阅读0次

    NSDateComponents *otherDay = [[NSCalendar currentCalendar] components:NSCalendarUnitEra | NSCalendarUnitYear | NSCalendarUnitMonth | NSCalendarUnitDay fromDate:aDate];

    NSDateComponents *today = [[NSCalendar currentCalendar] components:NSCalendarUnitEra | NSCalendarUnitYear | NSCalendarUnitMonth | NSCalendarUnitDay fromDate:[NSDate date]];

    if([today day] == [otherDay day] &&

      [today month] == [otherDay month] &&

      [today year] == [otherDay year] &&

      [today era] == [otherDay era]) {

        // 是今天

    }

    相关文章

      网友评论

        本文标题:iOS 判断时间是不是今天

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