+(NSString*)GetDetailTime{
//获得系统时间
NSDate * senddate=[NSDate date];
NSDateFormatter *dateformatter=[[NSDateFormatter alloc] init];
//[dateformatter setLocale:[NSLocale localeWithLocaleIdentifier:@""]];
[dateformatter setDateFormat:@"yyyy-MM-dd HH:mm:ss"];
NSString * morelocationString=[dateformatter stringFromDate:senddate];
// NSArray*array=[morelocationString componentsSeparatedByString:@"-"];
return morelocationString;
}
-(NSDate *)dateAfterDays:(int)days{
NSCalendar *calendar = [NSCalendar currentCalendar];
unsigned unitFlags = NSYearCalendarUnit | NSMonthCalendarUnit | NSDayCalendarUnit;
NSDateComponents *components = [calendar components:unitFlags fromDate:[NSDate date]];
[components setDay:([components day]+days)];
return [calendar dateFromComponents:components];
}
+(void)getNetTimeWithCompleteHandle:(void(^)(BOOL isSuccess,NSDate* date))complete{
AFHTTPSessionManager *manager = [AFHTTPSessionManager manager];
NSString * urlstr = @"https://www.baidu.com";
NSURL *url = [NSURL URLWithString:urlstr];
NSMutableURLRequest *muRequest = [[NSMutableURLRequest alloc]initWithURL:url cachePolicy:NSURLRequestReloadIgnoringLocalCacheData timeoutInterval:2.0f];
muRequest.HTTPMethod = @"GET";
NSURLSessionDataTask *task = [manager dataTaskWithRequest:muRequest completionHandler:^(NSURLResponse * _Nonnull response, id _Nullable responseObject, NSError * _Nullable error) {
NSHTTPURLResponse *httpResponse=(NSHTTPURLResponse *)response;
NSDictionary *dict=[httpResponse allHeaderFields];
NSString *time=[dict objectForKey:@"Date"];
NSString *timeStr=[time substringWithRange:NSMakeRange(5, 20)];
NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
NSTimeZone *timeZone = [NSTimeZone timeZoneWithName:@"GMT"];
NSLocale *local=[[NSLocale alloc]initWithLocaleIdentifier:@"en_US_POSIX"];
[formatter setLocale:local];
[formatter setTimeZone:timeZone];
[formatter setDateFormat:@"dd MMM yyyy HH:mm:ss"];
NSDate* date = [formatter dateFromString:timeStr];
long timesecond = date.timeIntervalSince1970;
if (error==nil) {
complete(YES,date);
}else{
complete(NO,date);
}
}];
[task resume];
}
NSDateFormatter *formater= [[ NSDateFormatter alloc]init];
[formater setDateFormat:@"yy/MM/dd"];
NSDate * expireD = [formater dateFromString:expireDate];
NSCalendar *gregorian = [[NSCalendar alloc] initWithCalendarIdentifier:NSCalendarIdentifierGregorian];
NSDateComponents *comps = [gregorian components:NSCalendarUnitEra fromDate:expireD1 toDate:expireD options:0];
NSInteger days = [comps day];
NSLog(@"%ld天",(long)days);