[英]How to get the Monday date of a week using the week number
How can I find out the Date of Monday if I pass the week number. 如果我通过周数,我怎么能找到星期一的日期。 For example, I need the Monday of the Week 24 of the year 例如,我需要一年中第24周的星期一
Fill out a NSDateComponents
object with the information you have. 使用您拥有的信息填写NSDateComponents
对象。 Then you can ask the current NSCalendar
what date corresponds to those components. 然后,您可以询问当前的NSCalendar
与这些组件对应的日期。
NSDateComponents *components = [NSDateComponents new];
components.weekday = 2;
components.weekOfYear = 24;
components.year = 2012;
NSDate *date = [[NSCalendar currentCalendar] dateFromComponents: components];
The weekday
property starts with Sunday = 1. weekday
属性从星期日= 1开始。
If you are on OS X 10.7 or newer you should use the property yearForWeekOfYear
instead of year
. 如果您使用的是OS X 10.7或更高版本,则应使用属性yearForWeekOfYear
而不是year
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.