Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我需要知道 iOS sdk 一年中的哪一天。我可以手动完成,但想知道有什么方法可以找到一年中的哪一天吗?我不是那个意思——一年有多少天。我需要知道输入日期的天数?
得到答案:) 请看下面的例子
NSCalendar *currentCalendar = [NSCalendar currentCalendar]; NSDate *today = [NSDate date]; NSInteger dc = [currentCalendar ordinalityOfUnit:NSDayCalendarUnit inUnit:NSYearCalendarUnit forDate:today]; NSLog(@"%d",dc);