//获取当地时间
- (NSString *)getCurrentTime {
NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
[formatter setDateFormat:@"yyyy-MM-dd"];
NSString *dateTime = [formatter stringFromDate:[NSDate date]];
return dateTime;
}
//将字符串转成NSDate类型
- (NSDate *)dateFromString:(NSString *)dateString {
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
[dateFormatter setDateFormat: @"yyyy-MM-dd"];
NSDate *destDate= [dateFormatter dateFromString:dateString];
return destDate;
}
//传入今天的时间,返回明天的时间
- (NSString *)GetTomorrowDay:(NSDate *)aDate {
NSCalendar *gregorian = [[NSCalendar alloc] initWithCalendarIdentifier:NSCalendarIdentifierGregorian];
NSDateComponents *components = [gregorian components:NSCalendarUnitWeekday | NSCalendarUnitYear | NSCalendarUnitMonth | NSCalendarUnitDay fromDate:aDate];
[components setDay:([components day]+1)];
NSDate *beginningOfWeek = [gregorian dateFromComponents:components];
NSDateFormatter *dateday = [[NSDateFormatter alloc] init];
[dateday setDateFormat:@"yyyy-MM-dd"];
return [dateday stringFromDate:beginningOfWeek];
}
网友评论