gpt4 book ai didi

objective-c - 比较两个表示日期的 NSString

转载 作者:行者123 更新时间:2023-12-03 17:35:15 25 4
gpt4 key购买 nike

我正在使用 NSSortDescriptor 来比较两个日期;效果很好。但我想比较两个日期字符串,例如“oct-22,2012 Morning”和“oct-22,2012 Evening”。

我用空格分隔每个字符串,并比较了没有上午/晚上字符串的日期,但我想显示上面的整个格式,即即将到来的状态是“2012 年 10 月 22 日上午”。

我用于比较两个日期的代码如下:

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;
}

有什么办法可以做到这一点吗?

最佳答案

最安全的方法是使用日期格式化程序将字符串转换为 NSDate 对象,然后使用标准技术进行比较。

关于objective-c - 比较两个表示日期的 NSString,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12996725/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com