gpt4 book ai didi

ios - NSDateComponents 周在 iOS8 上的工作方式不同

转载 作者:可可西里 更新时间:2023-11-01 03:51:52 26 4
gpt4 key购买 nike

NSDateComponents week 自 iOS8 以来已弃用。 Apple 建议根据上下文使用 weekOfMonthweekOfYear,但它们的工作方式不同。例如:

components1 = [calendar components:NSMonthCalendarUnit | NSWeekCalendarUnit | NSDayCalendarUnit
fromDate:[self date7DaysAgo]
toDate:[NSDate date]
options:0];

components1 返回 month = 0,week = 1,day = 0,weekOfMonthweekOfYear 都等于 2147483647(整数最大值)。

components2 = [calendar components:NSMonthCalendarUnit | NSWeekCalendarUnit | NSDayCalendarUnit
fromDate:[self date30DaysAgo]
toDate:[NSDate date]
options:0];

components2 返回 month = 1(我知道这取决于,但这只是一个例子),week = 0,day = 0,weekOfMonthweekOfYear 都等于2147483647(整数最大值)。

Week 返回某个时间段内的周数(如果是一周或多周),它与月或年中的周数完全不同。为什么苹果会建议改用这个?

最佳答案

使用 NSWeekOfMonthCalendarUnitNSWeekOfYearCalendarUnit 而不是 NSWeekCalendarUnit

关于ios - NSDateComponents 周在 iOS8 上的工作方式不同,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26120074/

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