簡體   English   中英

如何使用周數獲​​取一周的星期一日期

[英]How to get the Monday date of a week using the week number

如果我通過周數,我怎么能找到星期一的日期。 例如,我需要一年中第24周的星期一

使用您擁有的信息填寫NSDateComponents對象。 然后,您可以詢問當前的NSCalendar與這些組件對應的日期。

NSDateComponents *components = [NSDateComponents new];
components.weekday = 2;
components.weekOfYear = 24;
components.year = 2012;
NSDate *date = [[NSCalendar currentCalendar] dateFromComponents: components];

weekday屬性從星期日= 1開始。

如果您使用的是OS X 10.7或更高版本,則應使用屬性yearForWeekOfYear而不是year

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM