gpt4 book ai didi

ios - 在 objective-c 中使用日期月份和年份对日期数组进行排序

转载 作者:行者123 更新时间:2023-11-29 13:57:01 24 4
gpt4 key购买 nike

我想用日期对数组进行排序,但日期只按日期和月份排序,而不按年份排序我的代码:

NSArray *sortedArray = [arrClassSehedule sortedArrayUsingComparator:^NSComparisonResult(NSDictionary *obj1, NSDictionary *obj2) {
NSDate *d1 = [appSharedData.CommanFormatForConditional dateFromString: [obj1 objectForKey:@"scheduleStart"]];
NSDate *d2 = [appSharedData.CommanFormatForConditional dateFromString: [obj1 objectForKey:@"scheduleStart"]];
return [d1 compare: d2];
}];

它没有按日期正确排序。

最佳答案

好像打错了。

请将代码替换为

 NSDate *d2 = [appSharedData.CommanFormatForConditional dateFromString: [obj2 objectForKey:@"scheduleStart"]];

关于ios - 在 objective-c 中使用日期月份和年份对日期数组进行排序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55040428/

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