3
A
回答
3
- (BOOL)past5pm
{
NSCalendar *gregorianCalender = [[[NSCalendar alloc] initWithCalendarIdentifier:NSGregorianCalendar] autorelease];
NSDateComponents *components = [gregorianCalender components:NSHourCalendarUnit fromDate:[NSDate date]];
if([components hour] >= 17) // NSDateComponents uses the 24 hours format in which 17 is 5pm
return YES;
return NO;
}
0
试试这个
NSDateFormatter* dateFormatter = [[[NSDateFormatter alloc] init] autorelease];
[dateFormatter setDateFormat:@"hh:mm:ss a"];
NSDate* date = [NSDate date];
//Get the string date
NSString* str = [dateFormatter stringFromDate:date];
NSDate *firstDate = [dateFormatter dateFromString:@"05:00:00 PM"];
NSDate *secondDate = [dateFormatter dateFromString:str];
NSTimeInterval timeDifference = [secondDate timeIntervalSinceDate:firstDate];
NSLog(@"Time Diff - %f",timeDifference);
1
NSDateFormatter *dateFormatter = [[[NSDateFormatter alloc] init] autorelease];
[dateFormatter setDateFormat:@"HH.mm"];
NSDate *currentDate = [NSDate date];
NSString *curDate = [dateFormatter stringFromDate:currentDate];
if ([curDate doubleValue] >= 17.00)
{
//set your bool
}
0
你或许可以使用普通的C风格的代码,并获得差额作为一个整数,然后决定你需要从比较函数根据返回的内容羯羊的差异是积极的或消极的。你也可以用这种方式比较分钟。不要忘记导入time.h.
time_t now = time(NULL);
struct tm oldCTime;
localtime_r(&now, &oldCTime);
int hours = oldCTime.tm_hour;
int diff = 17-hours;
NSLog(@"Time difference is: %d.", diff);
相关问题
- 1. 固定时间比较
- 2. 比较当前时间与给定时间
- 3. JS比较当前和给定时间
- 4. Python与其他时间的当前时间比较
- 5. 比较字符串时间与当前时间android
- 6. MySql中与时间比较当前时间在使用SQL行
- 7. 比较PHP中的时间与当前时间
- 8. 如何比较当前时间与时间范围?
- 9. 比较当前的时间戳与mysql存储的时间戳
- 10. 的Unix脚本来比较时间戳与当前时间
- 11. 当与当前时间比较时搜索数组中的时间
- 12. 如何将HH:MM中的存储时间与当前时间进行比较?
- 13. 试图将日期选择器时间与当前时间进行比较ios
- 14. PHP - 将数据库日期时间与当前日期时间进行比较
- 15. Codeigniter:将MySql日期时间与当前日期进行比较
- 16. 使用jQuery比较服务器时间和当前时间
- 17. 比较日期时间到MySQL中的当前日期时间?
- 18. 比较数据库时间和当前时间
- 19. 比较当前时间和epg时间的结果
- 20. 使用日期时间添加小时,然后将此时间与当前时间进行比较
- 21. 比较时间与日期时间
- 22. 比较给定时间和当前时间的多个倒数计时器?
- 23. 比较之前定义的时间
- 24. 在android中比较输入日期和时间与当前日期和时间
- 25. Laravel 5.2雄辩比较日期时间与当前数据和时间
- 26. PHP strtotime()并根据两个给定时间比较当前时间
- 27. 通过比较当前时间和给定时间增加日期1天
- 28. 时间比较
- 29. 比较当前时间与WPF中的lambda表达式
- 30. SQL datetime与当前日期时间的比较
比较ObjC对象和double看起来有点不对,你不这么认为吗? – JustSid 2011-05-04 08:48:05
@JustSid Thankz buddy ...我做了编辑...现在它应该工作 – Aaron 2011-05-04 08:56:54