Get calendarweek of an NSDate according ISO 8601

♀尐吖头ヾ 提交于 2019-12-10 12:16:38

问题


is there a way to get calendarweek of an NSDate according ISO 8601. I think:

Datecomponents *dateComponents = [cal components:(NSWeekOfYearCalendarUnit ) fromDate: testDate ];
int calandarWeek =  [dateComponents weekOfYear];

uses a different algorithm.

ISO definition: CW1 is the first week in the year containing 4 day, CW start on Mondays


回答1:


I found out. It´s possible to configure the NSCalender:

[cal setFirstWeekday:2];            //week starts on Monday
[cal setMinimumDaysInFirstWeek:4];  //first week in the year containing 4 day


来源:https://stackoverflow.com/questions/9656833/get-calendarweek-of-an-nsdate-according-iso-8601

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!