相关疑难解决方法(0)

如何确定今天是否有NSDate?

如何检查一个NSDate属于今天?

我曾经使用前10个字符来检查它[aDate description].[[aDate description] substringToIndex:10]"YYYY-MM-DD"这样返回字符串我将字符串与返回的字符串进行了比较[[[NSDate date] description] substringToIndex:10].

有更快速和/或更好的方式来检查?

谢谢.

cocoa-touch objective-c nsdate nscalendar ios

149
推荐指数
10
解决办法
7万
查看次数

比较NSDate今天或昨天

嗯,我想这已被问了一千次,但由于某种原因,答案真的不起作用或有其他问题,....

无论如何这里是我"工作":

    NSCalendar *calendar = [NSCalendar currentCalendar];    
    NSDate *currentDate = [NSDate date];
    NSDateComponents *comps = [[NSDateComponents alloc] init];
    // set tomorrow (0: today, -1: yesterday)
    [comps setDay:0];
    NSDate *dateToday = [calendar dateByAddingComponents:comps toDate:currentDate options:0];
    [comps setDay:-1];
    NSDate *dateYesterday = [calendar dateByAddingComponents:comps toDate:currentDate options:0];
    [comps release];


NSString *todayString = [self.dateFormatter stringFromDate:dateToday] ;
NSString *yesterdayString = [self.dateFormatter stringFromDate:dateYesterday] ;
NSString *refDateString = [self.dateFormatter stringFromDate:info.date];

if ([refDateString isEqualToString:todayString]) 
{
    cell.title.text =  @"Today";
} else if ([refDateString isEqualToString:yesterdayString]) 
{
    cell.title.text =  @"Yesterday";
} else …
Run Code Online (Sandbox Code Playgroud)

iphone nsdate uitableview

9
推荐指数
2
解决办法
1万
查看次数

昨天在Objective-c中获得NSDate

我需要使用NSDate对象获取昨天的日期.任何的想法?

编辑:解决:

NSDate *yesterday = [NSDate dateWithTimeIntervalSinceNow:-86400];

cocoa-touch objective-c nsdate

9
推荐指数
2
解决办法
8607
查看次数