忘掉NSDateFormatter,NSDateComponents和NSTimeZone的麻烦,HRDate是从NSDate获取简单数据的简单API!
常量(如每小时秒数)
extern NSUInteger const HRDateHoursInDay;
extern NSUInteger const HRDateMinutesInHour;
extern NSUInteger const HRDateMinutesInDay;
extern NSUInteger const HRDateSecondsInMinute;
extern NSUInteger const HRDateSecondsInHour;
extern NSUInteger const HRDateSecondsInDay;
日期比较
-(BOOL)hrIsEqualToDateIgnoringTime:(nonnull NSDate *)date;
-(BOOL)hrIsToday;
-(BOOL)hrIsTomorrow;
-(BOOL)hrIsYesterday;
从日期获取所有!日期组件
@property (nonatomic, readonly) NSInteger hrEra;
@property (nonatomic, readonly) NSInteger hrDay;
@property (nonatomic, readonly) NSInteger hrMonth;
@property (nonatomic, readonly) NSInteger hrYear;
@property (nonatomic, readonly) NSInteger hrHour;
@property (nonatomic, readonly) NSInteger hrMinute;
@property (nonatomic, readonly) NSInteger hrSecond;
@property (nonatomic, readonly) NSInteger hrWeekday;
@property (nonatomic, readonly) NSInteger hrWeekdayOrdinal;
@property (nonatomic, readonly) NSInteger hrWeekOfMonth;
@property (nonatomic, readonly) NSInteger hrWeekOfYear;
@property (nonatomic, readonly) NSInteger hrYearForWeekOfYear;
@property (nonatomic, readonly) NSInteger hrNanosecond;
@property (nonatomic, readonly, nonnull) NSTimeZone *hrTimeZone;
@property (nonatomic, readonly, nonnull) NSCalendar *hrCalendar;
许多新的NSDate工厂方法
-(nonnull NSDate *)hrDateAfterDays:(NSInteger)days;
-(nonnull NSDate *)hrDateAfterHours:(NSInteger)hours;
+(nonnull NSDate *)hrYesterday;
+(nonnull NSDate *)hrTomorrow;
+(nullable NSDate *)hrDateFromString:(nonnull NSString *)string withDateFormat:(nonnull NSString *)dateFormat;
+(nullable NSDate *)hrDateFromString:(nonnull NSString *)string withDateStyle:(NSDateFormatterStyle)dateStyle andTimeStyle:(NSDateFormatterStyle)timeStyle;
//this method is awesome!
+(nullable NSDate *)hrDateWithHour:(NSUInteger)hour minute:(NSUInteger)minute second:(NSUInteger)second day:(NSUInteger)day month:(NSUInteger)month andYear:(NSUInteger)year;
//this method is awesome!
+(nullable NSDate *)hrDateWithDay:(NSUInteger)day month:(NSUInteger)month andYear:(NSUInteger)year;
+(nullable NSDate *)hrDateWithHourDifference:(NSInteger)hourDifference;
当然,还有日期字符串
-(nullable NSString *)hrDateStringWithDateFormat:(nonnull NSString *)dateFormat;
-(nonnull NSString *)hrDateStringWithDateStyle:(NSDateFormatterStyle)dateStyle andTimeStyle:(NSDateFormatterStyle)timeStyle;
有关NSDateFormatter、NSTimeZone、NSDateComponents和NSCalendar的功能,请参阅文档。
iOS 8.0或更高。
HRDate可通过CocoaPods安装。要安装它,只需将以下行添加到您的Podfile中
pod "HRDate"
Ivan Shevelev, [email protected]
HRDate可用MIT许可。有关更多信息,请参阅LICENSE文件。