这是我发现自己花了几个小时才弄明白并因此想与你分享的事情.
问题是:如何确定特定日期的一年中的哪一天?
例如,1月15日是第15天,12月31日是第365天,而不是闰年.
我想找到两个日期之间的总天数.
例如今天是01-01-2011(DD-MM-YYYY),第二个日期是(25-03-2011),我如何找到总天数?
NSDate *currentdate=[NSDate date];
NSLog(@"curretdate is ==%@",currentdate);
NSDateFormatter *tempFormatter1 = [[[NSDateFormatter alloc]init]autorelease];
[tempFormatter1 setDateFormat:@"dd-mm-YYYY hh:mm:ss"];
NSDate *toDate = [tempFormatter1 dateFromString:@"20-04-2011 09:00:00"];
NSLog(@"toDate ==%@",toDate);
Run Code Online (Sandbox Code Playgroud)