Kli*_*akM 6 iphone nsdatecomponents ios ios8
NSDateComponents
week
从iOS8开始不推荐使用.Apple建议使用weekOfMonth
或weekOfYear
取而代之,取决于上下文,但它们以不同的方式工作.例如:
components1 = [calendar components:NSMonthCalendarUnit | NSWeekCalendarUnit | NSDayCalendarUnit
fromDate:[self date7DaysAgo]
toDate:[NSDate date]
options:0];
Run Code Online (Sandbox Code Playgroud)
components1返回month = 0,week = 1,day = 0,weekOfMonth
并且weekOfYear
都等于2147483647(整数最大值).
components2 = [calendar components:NSMonthCalendarUnit | NSWeekCalendarUnit | NSDayCalendarUnit
fromDate:[self date30DaysAgo]
toDate:[NSDate date]
options:0];
Run Code Online (Sandbox Code Playgroud)
components2返回month = 1(我知道它取决于,但它只是一个例子),week = 0,day = 0,weekOfMonth
并且weekOfYear
都等于2147483647(整数最大值).
Week
返回某段时间内的周数(如果是一周或多数),它与月或一周中的周数完全不同.苹果为什么建议使用它呢?
归档时间: |
|
查看次数: |
1273 次 |
最近记录: |