0

IOS ここでは、日付に 2 時間または 3 時間を追加したいのですが、ここで試してみましたが、正しい結果が得られませんでした。誰か助けてください。

NSDate *mydate = birthDatePicker.date;
    NSTimeInterval secondsInEightHours = 2 * 60 * 60;
    NSDate *dateEightHoursAhead = [mydate dateByAddingTimeInterval:secondsInEightHours];
    NSLog(@"dateEightHoursAhead %@",dateEightHoursAhead);
4

1 に答える 1

0

このコードを日付ピッカーに使用します

- (IBAction)dobbtn:(id)sender {


    UIActionSheet *dateActionSheet = [[UIActionSheet alloc] initWithTitle:@"" delegate:self cancelButtonTitle:nil destructiveButtonTitle:nil otherButtonTitles:@"Done", nil];
    [dateActionSheet setActionSheetStyle:UIActionSheetStyleBlackTranslucent];
    [dateActionSheet showInView:self.view];
    [dateActionSheet setFrame:CGRectMake(0, 200, 320, 383)];

    UIDatePicker *dp = [[UIDatePicker alloc] initWithFrame:CGRectMake(0, 80, 100, 116)];


    dp.datePickerMode = UIDatePickerModeDate;

    [ dp addTarget: self action:
     @selector(dateChanged:)
  forControlEvents:UIControlEventValueChanged
     ];


    [ self.view addSubview: dp ];

    txtDob.font = [ UIFont fontWithName: @"Arial" size: 22.0 ];
    txtDob.textColor = [ UIColor blueColor ];

    txtDob.text = [ dp.date description ];

    [dp setDatePickerMode:UIDatePickerModeDate];


    [dateActionSheet addSubview:dp];

}



-(void) dateChanged: (id)sender
{
    UIDatePicker *control = (UIDatePicker *) sender;
    NSDate *selectedDate = control.date;
    txtDob.text = [ selectedDate description ];
}
于 2013-04-16T06:54:04.933 に答える