NSString *recordDate = [[NSUserDefaults standardUserDefaults]objectForKey:@"recordDate"];
if (recordDate.length != 0) {
NSDate *nowDate = [NSDate date]; // 当前时间
NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
[formatter setDateFormat:@"yyyy/MM/dd HH:mm:ss:SSS"];
NSString*timeString=[formatter stringFromDate: nowDate];
double timeDiff = 0.0;
NSDateFormatter *formatters = [[NSDateFormatter alloc] init];
[formatters setDateFormat:@"yyyy/MM/dd HH:mm:ss:SSS"];
NSDate *dateS = [formatters dateFromString:recordDate];
NSDateFormatter *formatterE = [[NSDateFormatter alloc] init];
[formatterE setDateFormat:@"yyyy/MM/dd HH:mm:ss:SSS"];
NSDate *dateE = [formatterE dateFromString:timeString];
timeDiff = [dateE timeIntervalSinceDate:dateS ];
int myInt = (int)timeDiff;
if (myInt < 20) {
MBProgressHUD *hud = [[MBProgressHUD alloc] init];
[self.view addSubview:hud];
hud.labelText = @"请勿频繁操作";//@"网络连接失败";
hud.mode = MBProgressHUDModeText;
[hud showAnimated:YES whileExecutingBlock:^{
sleep(1);
} completionBlock:^{
[hud removeFromSuperview];
}];
return;
}
}
#pragma mark-保存本地时间到沙盒
-(void)currentDateString{
NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
[formatter setDateFormat:@"yyyy/MM/dd HH:mm:ss:SSS"];
NSString*timeString=[formatter stringFromDate: [NSDate date]];
// NSDate *currentDate = [NSDate date];
// NSString *currentDateString = [NSString stringWithFormat:@"%ld", (long)[currentDate timeIntervalSince1970]];
[[NSUserDefaults standardUserDefaults] setObject:timeString forKey:@"recordDate"];
[[NSUserDefaults standardUserDefaults] synchronize];
}