Sometimes we may obtain some information from the server, but there is a time limit for this information. We need to set the data to invalid or directly Delete after the specified time. The following is an NSDate-(IBAction) ButtonMethod :( id) sender {// simulate the start of the effective time NSDate * dateNow = [NSDate date]; NSDateFormatter * dateFormmatter = [[NSDateFormatter alloc] init]; [dateFormmatter setDateFormat: @ "yyyy-MM-dd HH: mm: ss"]; NSString * dateStr = [dateFormmatter stringFromDate: dateNow]; [dateStr writeToFile: [self timePath] atomically: YES encoding: NSUTF8StringEncoding error: nil];}-(IBAction) ButtonMethod2 :( id) s Ender {// simulate whether NSDate * dateNow = [NSDate date] can be operated within the effective time; NSDateFormatter * dateFormmatter = [[NSDateFormatter alloc] init]; [dateFormmatter setDateFormat: @ "yyyy-MM-dd HH: mm: ss"]; NSString * dateStrNow = [dateFormmatter stringFromDate: dateNow]; NSString * dateStrPre = [NSString stringWithContentsOfFile: [self timePath] encoding: NSUTF8StringEncoding error: nil]; if ([self convertDateString: dateStrNow]-[self con VertDateString: dateStrPre]> = 60) {NSLog (@ "more than 60 seconds"); // you can delete data, or prompt the user} else {NSLog (@ "less than 60 seconds"); // perform the operation}-(long) convertDateString :( NSString *) aString {// format: yyyy-MM-dd HH: mm: ss. Of course, you can change its format to NSArray * dateArray = [aString componentsSeparatedByString: @ ""]; NSString * dayStr = [dateArray objectAtIndex: 1]; NSArray * dayArray = [dayStr componentsSeparatedByString: @ ":"]; long totalS Econds = 0; totalSeconds + = [[dayArray objectAtIndex: 0] intValue] * 60*60; totalSeconds + = [[dayArray objectAtIndex: 1] intValue] * 60; totalSeconds + = [[dayArray objectAtIndex: 2] intValue]; return totalSeconds;} You can also use an nst to test whether the validity period has exceeded.