作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在尝试比较今天是否有时间。我使用了NSCalendar [Calender isDateInToday:date]
方法。但是,只是经过午夜的时间未通过测试。
时间00:14:05返回否,但21:43:47返回是。
我的测试代码:
NSCalendar *cal = [NSCalendar calendarWithIdentifier: NSCalendarIdentifierGregorian];
NSLog(@"date: %@, isInToday: %i, Currernt date: %@", o.deliverDate, [cal isDate:o.deliverDate inSameDayAsDate:[TimeIntervals getCurrerntLocalTime]], [TimeIntervals getCurrerntLocalTime]);
[TimeIntervals getCurrerntLocalTime]
返回当前本地系统时间:
+(NSDate *)getCurrerntLocalTime{
NSDate* sourceDate = [NSDate date];
NSTimeZone* sourceTimeZone = [NSTimeZone timeZoneWithAbbreviation:@"GMT"];
NSTimeZone* destinationTimeZone = [NSTimeZone systemTimeZone];
NSInteger sourceGMTOffset = [sourceTimeZone secondsFromGMTForDate:sourceDate];
NSInteger destinationGMTOffset = [destinationTimeZone secondsFromGMTForDate:sourceDate];
NSTimeInterval interval = destinationGMTOffset - sourceGMTOffset;
NSDate* destinationDate = [[NSDate alloc] initWithTimeInterval:interval sinceDate:sourceDate];
return destinationDate;
}
date: 2015-02-09 00:14:05 +0000, isInToday: 0, Currernt date: 2015-02-09 19:07:43 +0000
date: 2015-02-09 21:43:47 +0000, isInToday: 1, Currernt date: 2015-02-09 19:07:44 +0000
最佳答案
您应该使用当前的日历:
迅速:
let isToday = NSCalendar.currentCalendar().isDateInToday(date)
关于ios - 日历-isDateInToday:date 00:15今天不在吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28423431/
我正在尝试比较今天是否有时间。我使用了NSCalendar [Calender isDateInToday:date]方法。但是,只是经过午夜的时间未通过测试。 时间00:14:05返回否,但21:4
因为这篇文章与给定日期与“今天的日期”的比较有关,请记住我是在 2017-01-26 上发布的 基本上,我正在做以下事情: 从服务器获取 ISO DATE 将所述日期转换为 NSDate 使用 NSC
我是一名优秀的程序员,十分优秀!