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. 如何将GDKEvent时间戳与当前时间进行比较?
- 3. 如何比较两个给定时间与当前时间?
- 4. 比较当前时间与给定时间
- 5. 如何比较当前时间与当天的时间
- 6. 比较字符串与当前时间
- 7. PHP比较DateTime与当前时间
- 8. 与当前时间比较SQL
- 9. 使用NodaTime如何比较当地时间和固定时间?
- 10. JS比较当前和给定时间
- 11. 如何比较当前时间与时间范围?
- 12. 的Unix脚本来比较时间戳与当前时间
- 13. MySql中与时间比较当前时间在使用SQL行
- 14. 比较PHP中的时间与当前时间
- 15. 比较时间给每个李与当前时间
- 16. Python与其他时间的当前时间比较
- 17. 与当前时间比较GregorianCalendar的时间
- 18. 如何比较当前时间与MySQL中的时间变量
- 19. 比较当前的时间戳与mysql存储的时间戳
- 20. 比较字符串时间与当前时间android
- 21. 将小时和分钟与当前时间进行比较
- 22. 比较JQuery中给定时期之间的当前时间
- 23. 将时间与Perl比较
- 24. 当与当前时间比较时搜索数组中的时间
- 25. 将python中的当前时间与xml中的时间进行比较
- 26. PHP - 将数据库日期时间与当前日期时间进行比较
- 27. 如何将MySQL中的时间与当前时间进行比较php
- 28. 如何将当前时间与PHP中的旧时间进行比较
- 29. mysql - 将当前时间戳与两个时间范围进行比较
- 30. 有没有办法将当前时间与mysql保存时间进行比较
比较ObjC对象和double看起来有点不对,你不这么认为吗? – JustSid 2011-05-04 08:48:05
@JustSid Thankz buddy ...我做了编辑...现在它应该工作 – Aaron 2011-05-04 08:56:54