「ios開発」経過時間差を計算するコード

iosコード
-(BOOL)HanOrderTimer{
userdefault = NSUserDefault;
if ([userdefault objectForKey:@"LoginTime"]) {
//日付フォーマット
NSDateFormatter *cftFormatter = [[NSDateFormatter alloc]init];
[cftFormatter setDateFormat:@"yyyy-MM-dd HH:mm:ss"];
//ログイン時間文字列
NSString *orderedTime = [userdefault valueForKey:@"LoginTime"];
//ログイン時間
NSDate *orderedDate = [cftFormatter dateFromString:orderedTime];
NSTimeZone *zone1 = [NSTimeZone systemTimeZone];
NSInteger interval1 = [zone1 secondsFromGMTForDate:orderedDate];
NSDate *localDate1 = [orderedDate dateByAddingTimeInterval:interval1];

//現在時刻
NSDate *currentDate = [NSDate date];
NSTimeZone *zone2 = [NSTimeZone systemTimeZone];
NSInteger interval2 = [zone2 secondsFromGMTForDate:currentDate];
NSDate *localDate2 = [currentDate dateByAddingTimeInterval:interval2];
double intervalTime = [localDate2 timeIntervalSinceReferenceDate] – [localDate1 timeIntervalSinceReferenceDate];
int iTime = (int)intervalTime;
if (iTime>=900)
return YES;
}else{
return NO;
};
}else{
return NO;
}
}

IOS

Posted by arkgame