0

私は以下のコードを使用して、コードがシミュレーターで正常に機能する残り時間を計算していますが、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デバイスで時間計算が正常に機能します。アイデアやヘルプ

4

1 に答える 1

1

NSDateFormatter から' zzz ' を削除し、日付文字列から ' IST ' を削除した後、iPad で動作します。NSDateFormatter と日付文字列からタイムゾーンを削除すると、機能します。

于 2012-10-26T06:56:38.337 に答える