获取日期

NSDate *date =[NSDate date];//

NSDateFormatter *formatter = [[NSDateFormatter alloc]init];

[formatter setDateFormat:@"yyyy"];

NSInteger currentYear=[[formatter stringFromDate:date] integerValue];

[formatter setDateFormat:@"MM"];

NSInteger currentMonth=[[formatter stringFromDate:date]integerValue];

NSString *YY = [NSString stringWithFormat:@"trueLoveGroupPopYY%@",key];

NSString *MM = [NSString stringWithFormat:@"trueLoveGroupPopMM%@",key];

NSInteger storageYear = [[NSUserDefaults standardUserDefaults] integerForKey:YY];

NSInteger storageMonth = [[NSUserDefaults standardUserDefaults] integerForKey:MM];

if (currentYear == storageYear) {

if (currentMonth == storageMonth) {//存过当前月份表示已经显示过

return NO;

}else{

[[NSUserDefaults standardUserDefaults] setInteger:currentYear forKey:YY];

[[NSUserDefaults standardUserDefaults] setInteger:currentMonth forKey:MM];

[[NSUserDefaults standardUserDefaults] synchronize];

return YES;

}

}else{

[[NSUserDefaults standardUserDefaults] setInteger:currentYear forKey:YY];

[[NSUserDefaults standardUserDefaults] setInteger:currentMonth forKey:MM];

[[NSUserDefaults standardUserDefaults] synchronize];

return YES;

}

return NO;

你可能感兴趣的:(获取日期)