【发布时间】:2023-03-29 05:31:01
【问题描述】:
我使用NSSortDescriptor 比较两个日期;它运作良好。但我想比较两个日期字符串,如“oct-22,2012 Morning”和“oct-22,2012 Evening”。
我用空格分隔每个字符串并比较没有早/晚字符串的日期,但我想显示上面的整个格式,即即将到来的状态是“oct-22,2012 Morning”。
我比较两个日期的代码如下:
NSSortDescriptor *sortDescriptor = [[NSSortDescriptor alloc] initWithKey: @"convertedDate" ascending:YES] ;
[sortArray sortUsingDescriptors:[NSArray arrayWithObject:sortDescriptor]];
GetBuddiesObject *datewiseSortObj;
if([sortArray count]>0)
{
datewiseSortObj=[sortArray objectAtIndex:0];
obj.flying=datewiseSortObj.flying;
obj.when=datewiseSortObj.when;
obj.herenow=datewiseSortObj.herenow;
obj.convertedDate=datewiseSortObj.convertedDate;
}
有什么办法吗?
【问题讨论】:
-
你能告诉我你是如何排序/比较日期的吗?你用这种格式的'20121021'来比较吗?
-
我正在使用这种格式 2012-10-21 04:00:00 +0000
-
是否可以更改您的日期格式以与“20121021”进行比较,以便您可以按整数进行比较,并且要添加早上/中午/晚上的比较,您可以再添加一位数字分别是1/2/3..从最后一位排序后,你可以知道它是早上/中午/甚至......
标签: objective-c cocoa cocoa-touch nsstring nsdate