diff --git a/YYKit/Base/Foundation/NSDate+YYAdd.h b/YYKit/Base/Foundation/NSDate+YYAdd.h index d9ecb11d..54317d2b 100644 --- a/YYKit/Base/Foundation/NSDate+YYAdd.h +++ b/YYKit/Base/Foundation/NSDate+YYAdd.h @@ -30,6 +30,7 @@ NS_ASSUME_NONNULL_BEGIN @property (nonatomic, readonly) NSInteger minute; ///< Minute component (0~59) @property (nonatomic, readonly) NSInteger second; ///< Second component (0~59) @property (nonatomic, readonly) NSInteger nanosecond; ///< Nanosecond component +@property (nonatomic, readonly) NSInteger dayOfYear; ///< DayOfYear component (0~365/366) @property (nonatomic, readonly) NSInteger weekday; ///< Weekday component (1~7, first day is based on user setting) @property (nonatomic, readonly) NSInteger weekdayOrdinal; ///< WeekdayOrdinal component @property (nonatomic, readonly) NSInteger weekOfMonth; ///< WeekOfMonth component (1~5) diff --git a/YYKit/Base/Foundation/NSDate+YYAdd.m b/YYKit/Base/Foundation/NSDate+YYAdd.m index 3729088d..e071af35 100644 --- a/YYKit/Base/Foundation/NSDate+YYAdd.m +++ b/YYKit/Base/Foundation/NSDate+YYAdd.m @@ -46,6 +46,10 @@ - (NSInteger)nanosecond { return [[[NSCalendar currentCalendar] components:NSCalendarUnitSecond fromDate:self] nanosecond]; } +- (NSInteger)dayOfYear{ + return [[NSCalendar currentCalendar] ordinalityOfUnit:NSCalendarUnitDay inUnit:NSCalendarUnitYear forDate:self]; +} + - (NSInteger)weekday { return [[[NSCalendar currentCalendar] components:NSCalendarUnitWeekday fromDate:self] weekday]; }