根据 ISO 8601 获取 NSDate 的日历周 [英] Get calendarweek of an NSDate according ISO 8601

查看:64
本文介绍了根据 ISO 8601 获取 NSDate 的日历周的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有办法根据 ISO 8601 获取 NSDate 的日历周.我认为:

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

使用不同的算法.

ISO 定义:CW1 是一年中的第一周,包含 4 天,CW 从星期一开始

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

推荐答案

我发现了.可以配置 NSCalender:

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

这篇关于根据 ISO 8601 获取 NSDate 的日历周的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆