当年奋不顾身跳的那些~坑

iOS 判断时间是不是今天

2021-05-31  本文已影响0人  ios_暗夜行者

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]) {

    // 是今天

}

上一篇下一篇

猜你喜欢

热点阅读