2010-12-07 20 views
0

時刻を表示するボタンがあります。 次に、日付ピッカーのサブビューを読み込むと、それは常に2時間前に設定されます。 このようなもの: 日付ボタン:10:31日付ピッカー:12:31 日付ピッカーの時間を変更した後:13:31日付ボタンが11:31に変更されます。時刻限定UIDatePickerは現在時刻の2時間前に表示されます

コード:ビューから

-(IBAction) timeClicked 
{ 
    [[NSBundle mainBundle] loadNibNamed:@"timePicker" owner:self options:nil]; 
    //timeView = [[UIView alloc]initWithNibName:@"timePicker" bundle:nil]; 
    [timeView setFrame:CGRectMake(0, 480, 320, 431)]; 
    NSLog(@"time clicked date: %@", select); 
    NSDate* sourceDate = [NSDate date]; 

    NSTimeZone* sourceTimeZone = [NSTimeZone timeZoneWithName:@"Jerusalem"]; 
    NSTimeZone* destinationTimeZone = [NSTimeZone systemTimeZone]; 

    NSInteger sourceGMTOffset = [sourceTimeZone secondsFromGMTForDate:sourceDate]; 
    NSInteger destinationGMTOffset = [destinationTimeZone secondsFromGMTForDate:sourceDate]; 
    NSTimeInterval interval = destinationGMTOffset - sourceGMTOffset; 

    NSDate* destinationDate = [[[NSDate alloc] initWithTimeInterval:interval sinceDate:sourceDate] autorelease]; 


    //[timePick setTime:destinationDate animated:YES]; 
    timePick.date=destinationDate; 
    NSLog(@"befoer delegate"); 
    //[timeView setDelegate:self]; 
    [self.view addSubview:timeView]; 
    CGRect frame = timeView.frame; 
    frame.origin.y = 110; 
    [UIView beginAnimations:nil context:NULL]; 
    timeView.frame = frame; 
    [UIView commitAnimations]; 
    NSLog(@"after"); 

} 


-(IBAction) done 
{ 
    select = [timePick date]; 
    [UIView beginAnimations:@"RemoveDatePicker" context:NULL]; 
    [UIView setAnimationDidStopSelector:@selector(transitionDidStop:finished:context:)]; 
    CGRect rect = timeView.frame; 
    rect.origin.y = 460; 
    timeView.frame = rect; 
    [UIView commitAnimations]; 

} 

- (void)transitionDidStop:(NSString *)animationID finished:(BOOL)finished context:(void *)context 
{ 
    if ([animationID isEqualToString:@"RemoveDatePicker"]){ 
     [timeView removeFromSuperview]; 
     NSLog(@"RemoveDatePicker"); 
    } 

} 


-(IBAction) timeChanged 
{ 
    select =[timePick date]; 

    [timeButton setTitle:[Path stringFromTime:select] forState:UIControlStateNormal]; 


    //[timeButton setTitle:@"time" forState:UIControlStateNormal]; 
} 

+(NSString *) stringFromTime: (NSDate *) date 
{ 

    NSString * stringDate = [date description]; 
    stringDate = [[stringDate substringFromIndex:11] substringToIndex:5]; 
    NSLog(@"[Path]stringTime: %@", stringDate); 
    return stringDate; 

} 

でし負荷:私はiPhoneのためか、Objective-Cで開発されていませんでしたので、私は上100%ではないんだものの

NSDate* sourceDate = [NSDate date]; 

    NSTimeZone* sourceTimeZone = [NSTimeZone timeZoneWithName:@"Jerusalem"]; 
    NSTimeZone* destinationTimeZone = [NSTimeZone systemTimeZone]; 

    NSInteger sourceGMTOffset = [sourceTimeZone secondsFromGMTForDate:sourceDate]; 
    NSInteger destinationGMTOffset = [destinationTimeZone secondsFromGMTForDate:sourceDate]; 
    NSTimeInterval interval = destinationGMTOffset - sourceGMTOffset; 

    NSDate* destinationDate = [[[NSDate alloc] initWithTimeInterval:interval sinceDate:sourceDate] autorelease]; 

    timeModeChange.selectedSegmentIndex=1; 
    select=[[NSDate alloc]initWithDate:destinationDate ]; 
     NSLog(@"date %@", select); 
    [timeButton setTitle:[Path stringFromTime:select] forState:UIControlStateNormal]; 

答えて

0

解決済み。 stringFromTimeに問題がありました - [date discription]が間違った値を返しました。

0

文法などが含まれていますが、入力時点をGMT(またはUTC)に変換している場合と、そうでない場合に翻訳することがあるようです。選択したタイムゾーンがイスラエル/エルサレムのUTC + 2(+3 IST)であるため、これは2時間の不一致を説明することができます。私は時間を "移動"せず、それが役立つかどうかを見てみようと思います。もしそうなら、あなたは少なくとも問題を発見した、と私は言うだろう。

+0

私たちがタイムゾーンを選択する前に、日付ボタンが作動時間よりも2時間早く設定されていて、日付ピッカーがリアルタイムに設定されていたとしても、同じ問題です。 –

関連する問題