Began
/// 用于只获取每个月当中的哪一号
- (NSInteger)getDay {
//设置成中国阳历
NSCalendar *calendar = [[NSCalendar alloc] initWithCalendarIdentifier:NSCalendarIdentifierGregorian];
NSDateComponents *comps = [calendar components:NSCalendarUnitDay fromDate:[NSDate date]];
//获取日期中的某一天
NSInteger day = comps.day;
return day;
}
- 注意:
如果是想知道现在是几月可以把NSCalendarUnitDay改为NSCalendarUnitMouth即可,当然也可以全写为
NSDateComponents *comps = [calendar components:NSCalendarUnitYear | NSCalendarUnitMonth | NSCalendarUnitDay | NSCalendarUnitWeekday | NSCalendarUnitHour | NSCalendarUnitMinute | NSCalendarUnitSecond fromDate:[NSDate date]];
End