NSDate *date;
date = [[NSUserDefaultsstandardUserDefaults] objectForKey:@"date"];
if (date) {
NSLog(@"存在");
}else {
date = [NSDatedate];
[[NSUserDefaultsstandardUserDefaults] setObject:date forKey:@"date"];
NSLog(@"不存在");
}
NSDateFormatter *formater = [[NSDateFormatteralloc] init];
[formater setDateFormat:@"yyyy年MM月dd号 HH:mm:ss"];
NSString *dateStr = [formaterstringFromDate:date];
NSLog(@"第一次;;%@",dateStr);
// 现在的时间
NSDate *nowDate = [NSDatedate];
NSString *nowDateStr = [formaterstringFromDate:nowDate];
NSLog(@"nowDatestr==%@",nowDateStr);
// 计算差值,这次登录距离上次登录的差值,单位是秒
double intercalTime = [nowDatetimeIntervalSinceReferenceDate] - [datetimeIntervalSinceReferenceDate];
NSLog(@"差值是:%f秒",intercalTime);
// 接下来,如果秒数大于一周,一个月,再做相应的事情
新闻热点
疑难解答