You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
58 lines
1.8 KiB
58 lines
1.8 KiB
// |
|
// NSDate+EBAdd.m |
|
// EBCalendarViewDemo |
|
// |
|
// Created by HoYo on 2018/4/28. |
|
// Copyright © 2018年 HoYo. All rights reserved. |
|
// |
|
|
|
#import "NSDate+EBAdd.h" |
|
|
|
@implementation NSDate (EBAdd) |
|
- (NSInteger)year { |
|
return [[[NSCalendar currentCalendar] components:NSCalendarUnitYear fromDate:self] year]; |
|
} |
|
|
|
- (NSInteger)month { |
|
return [[[NSCalendar currentCalendar] components:NSCalendarUnitMonth fromDate:self] month]; |
|
} |
|
|
|
- (NSInteger)day { |
|
return [[[NSCalendar currentCalendar] components:NSCalendarUnitDay fromDate:self] day]; |
|
} |
|
|
|
- (NSInteger)weekday { |
|
return [[[NSCalendar currentCalendar] components:NSCalendarUnitWeekday fromDate:self] weekday]; |
|
} |
|
|
|
- (BOOL)isToday { |
|
if (fabs(self.timeIntervalSinceNow) >= 60 * 60 * 24) return NO; |
|
return [NSDate new].day == self.day; |
|
} |
|
|
|
- (NSUInteger)numberOfDaysInMonth { |
|
return [[[NSCalendar currentCalendar] initWithCalendarIdentifier:NSCalendarIdentifierGregorian] rangeOfUnit:NSCalendarUnitDay inUnit:NSCalendarUnitMonth forDate:self].length; |
|
} |
|
|
|
- (NSString *)stringWithFormat:(NSString *)format { |
|
NSDateFormatter *formatter = [[NSDateFormatter alloc] init]; |
|
[formatter setDateFormat:format]; |
|
[formatter setLocale:[NSLocale currentLocale]]; |
|
return [formatter stringFromDate:self]; |
|
} |
|
|
|
- (NSDate *)dateByAddingMonths:(NSInteger)months { |
|
NSCalendar *calendar = [NSCalendar currentCalendar]; |
|
NSDateComponents *components = [[NSDateComponents alloc] init]; |
|
[components setMonth:months]; |
|
return [calendar dateByAddingComponents:components toDate:self options:0]; |
|
} |
|
|
|
+ (NSDate *)dateWithString:(NSString *)dateString format:(NSString *)format { |
|
NSDateFormatter *formatter = [[NSDateFormatter alloc] init]; |
|
[formatter setDateFormat:format]; |
|
return [formatter dateFromString:dateString]; |
|
} |
|
|
|
|
|
@end
|
|
|