iOS判断两个时间戳是否同一天
程序员文章站
2024-03-20 21:23:16
...
- (BOOL)isSameDay:(long)iTime1 Time2:(long)iTime2
{
//传入时间毫秒数
NSDate *pDate1 = [NSDate dateWithTimeIntervalSince1970:iTime1/1000];
NSDate *pDate2 = [NSDate dateWithTimeIntervalSince1970:iTime2/1000];
NSCalendar* calendar = [NSCalendar currentCalendar];
unsigned unitFlags = NSCalendarUnitYear | NSCalendarUnitMonth | NSCalendarUnitDay;
NSDateComponents* comp1 = [calendar components:unitFlags fromDate:pDate1];
NSDateComponents* comp2 = [calendar components:unitFlags fromDate:pDate2];
return [comp1 day] == [comp2 day] &&
[comp1 month] == [comp2 month] &&
[comp1 year] == [comp2 year];
}
下一篇: 事务---关于事务的一系列知识