NSDate转换NSString
NSDate *date = [NSDate date];
NSDateFormatter *dateFor = [[NSDateFormatter alloc]init];
dateFor.dateFormat = @"yyyy/MM/dd HH:mm:ss"; //hh 12小时制 HH 24小时制
NSString *dateStr = [dateFor stringFromDate:date];
NSString转换NSDate
NSDate *strForDate = [self stringToDate:@"2015-01-01 10:30:20" formatter:@"yyyy-MM-dd HH:mm:ss"];
- (NSDate *)stringToDate:(NSString *)datetime formatter:(NSString*)format {
NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
[formatter setFormatterBehavior:NSDateFormatterBehavior10_4];
[formatter setDateFormat:format];//yyyy-MM-dd
NSDate *date = [formatter dateFromString:datetime];
#if !__has_feature(objc_arc)
[formatter release];
#endif
return date;
}
//计算两个时间点差(以分钟为单位)
-(void)saveClickNowDate
{
NSDate *date1 = [NSDate date];
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc]init];
dateFormatter.dateFormat = @"yyyy-MM-dd HH:mm:ss"; //hh 12小时制 HH 24小时制
NSDate *date = [dateFormatter dateFromString:@"2016-12-16 00:37:20"];
[[NSUserDefaults standardUserDefaults] setObject:date forKey:@"clickDate"];
[[NSUserDefaults standardUserDefaults] setObject:date1 forKey:@"clickDate1"];
[[NSUserDefaults standardUserDefaults] synchronize];
}
//取出上次点击时间,判断和现在间隔多少分钟
-(BOOL)checkDate:(NSString*)timeIntrerl
{
NSDate *clickDateStr = [[NSUserDefaults standardUserDefaults] objectForKey:@"clickDate"];
NSDate *clickDateStr1 = [[NSUserDefaults standardUserDefaults] objectForKey:@"clickDate1"];
NSTimeInterval time = [[NSDate date] timeIntervalSinceDate:clickDateStr];
NSTimeInterval time1 = [[NSDate date] timeIntervalSinceDate:clickDateStr1];
// int days = ((int)time)/(3600*24);
//
// int hours = ((int)time)%(3600*24)/3600;
//
// int minutes = ((int)time)%(3600*24)%3600/60;
//
// int seconds = ((int)time)%(3600*24)%3600%60;
int timeIn = [@"5" intValue];
long long m = timeIn*60;
if ((time) >= m)
{
return YES;
}
return NO;
}