我如何從appEnterBackground獲取日期並從appEnterForeground中拿走,然後顯示標籤中的差異。 這是到目前爲止我的代碼..iphone - 時間(應用程序隱藏)和時間(應用程序出現)之間的差異
**.h**
NSTimeInterval appEnteredBackground;
NSTimeInterval appEnteredForeground;
NSTimeInterval difference;
**.m**
- (void)applicationDidEnterBackground:(UIApplication *)application
{
appEnteredBackground = [NSDate timeIntervalSinceReferenceDate];
}
- (void)applicationWillEnterForeground:(UIApplication *)application
{
appEnteredForeground = [NSDate timeIntervalSinceReferenceDate];
difference = appEnteredForeground - appEnteredBackground;
NSLog(@"Duration is %@",[NSDate dateWithTimeIntervalSinceReferenceDate: difference]);
NSLog(@"Duration is %@", [NSString stringWithFormat:@"%f", difference]);
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
[dateFormatter setDateStyle:NSDateFormatterMediumStyle];
NSString *time = [NSString stringWithFormat:@"%f", difference]; **//ERROR HERE (variable not used)**
[dateFormatter release];
}
任何幫助將是非常美妙的
什麼錯誤? – onnoweb 2011-05-27 14:59:41
@onnoweb:** // ERROR HERE(變量未使用)**我想將'差異'的值存入標籤或字符串中,以便我可以在計算中使用它... – myles 2011-05-27 15:06:43
[timeIntervalSinceNow help !!](http://stackoverflow.com/questions/6144966/timeintervalsincenow-help) – 2011-05-27 15:14:52