How to display picker view in MM-dd-yy format in iOS 5.1?

后端 未结 5 1258
挽巷
挽巷 2020-12-06 10:51

In my application i am using pickerview

My problem is that when in iOS 4.3 Picker view comes MM-dd-yy format,

相关标签:
5条回答
  • 2020-12-06 11:39

    For this you can make your custom picker.

    Or you want to format the date then use this code..

    NSDateFormatter *dateFormat = [[NSDateFormatter alloc] init];
    [dateFormat setDateFormat:@"MM-dd-yy"];
    NSString *date = [dateFormat stringFromDate:datePicker.date];    
    NSLog(@"date is >>> , %@",date);
    
    0 讨论(0)
  • 2020-12-06 11:42

    Check this

    UIDatePicker *datePicker = [[UIDatePicker alloc] initWithFrame:CGRectMake(0, 250, 325, 300)];
    
     datePicker.datePickerMode = UIDatePickerModeDate;
    
     datePicker.date = [NSDate date];
    
     [datePicker addTarget:self   action:@selector(LabelChange:)forControlEvents:UIControlEventValueChanged];
    
     [self.view addSubview:datePicker];
    
     [datePicker release];
    
    0 讨论(0)
  • 2020-12-06 11:47

    Change region to United states i.e locale settings

    NSLocale *locale = [[NSLocale alloc] initWithLocaleIdentifier:@"US"];
            [datePicker setLocale:locale];
    
    0 讨论(0)
  • 2020-12-06 11:50

    In iOS 5.1 display UIDatePicker as it is in 4.3

    Your and mine both of code is same but in my application UIDatePicker display
    with MM-dd-yyyy

    Use it ...may be helpful for you.

       self.DatePicker= [[UIDatePicker alloc] initWithFrame:CGRectMake(0, 0, 320, 216)];
        self.DatePicker.datePickerMode = UIDatePickerModeDate;
        [self.DatePicker addTarget:self
                       action:@selector(SetDatePickerTime:)
             forControlEvents:UIControlEventValueChanged];
        [self.asheet addSubview:self.DatePicker];
    
    0 讨论(0)
  • 2020-12-06 11:51

    My all code works is fine,

    Problem is with Settings,

    My region format is set to india and change it to United state,

    All works fine.....

    0 讨论(0)
提交回复
热议问题