Reputation: 975
i am using below code to calculate remaining time that code working good on Simulator but it gives all zero value to day hours minutes and seconds on iPad device
`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];
value of final date is zero on device but right on simulator.
My app is universal app the time calculation working fine on iPhone Device. Any idea or help
Upvotes: 0
Views: 598
Reputation: 975
After removing 'zzz' from NSDateFormatter and 'IST' from date string it works on iPad.But still have a question that why the previous code works on iPhone and not in iPad? After removing time zone from NSDateFormatter and date string it works.
Upvotes: 1