我正在使用下面的代码来计算该代码在模拟器上运行良好的剩余时间,但它在 iPad 设备上为一天的小时分钟和秒提供了所有零值
`NSTimeInterval remainingSec = [databaseDate timeIntervalSinceNow];
if (!timer || remainingSec <= 0) {
[timer invalidate];
timer = nil;
// getting time from database
NSLocale *indianEnglishLocale = [[NSLocale alloc] initWithLocaleIdentifier:@"en_IN"];
NSTimeZone *timeZone = [NSTimeZone timeZoneWithName:@"Asia/Kolkata"];
NSDateFormatter *dateFrmattr = [[NSDateFormatter alloc] init];
[dateFrmattr setLocale:indianEnglishLocale];
[dateFrmattr setDateFormat:@"V"];
[dateFrmattr setTimeZone:timeZone];
dateFrmattr.timeStyle = NSDateFormatterNoStyle;
dateFrmattr.dateFormat = @"MM/dd/yyyy HH:mm:ss zzz";
NSDate *finalDate = [dateFrmattr dateFromString:@"11/01/2012 10:00:00 IST"];
// NSDate *startDate = [[NSDate alloc] init];
self.databaseDate = [[NSDate alloc] init];;
remainingSec = [finalDate timeIntervalSinceDate:databaseDate];
timer = [NSTimer scheduledTimerWithTimeInterval:1.0 target:self
selector:@selector(showClock)
userInfo:nil
repeats:YES];
}
//NSInteger remainder = ((NSInteger)remainingSec)% 3600;
NSInteger days = remainingSec/86400;
NSInteger int1 = ((NSInteger)remainingSec) % 86400;
NSInteger hours = int1/3600;
NSInteger int2 = int1 % 3600;
NSInteger minutes = int2/60;
NSInteger seconds = int2 % 60;
clockLabel.text = [NSString stringWithFormat:@" %02d : %02d : %02d : %02d ", days,hours, minutes, seconds];
最终日期的值在设备上为零,但在模拟器上。
我的应用程序是通用应用程序,时间计算在 iPhone 设备上运行良好。任何想法或帮助