0
  if (_providerDatePicker) _providerDatePicker.hidden =
     !_providerDatePicker.hidden; if (_providerToolbar)
     _providerToolbar.hidden = !_providerToolbar.hidden; float screenWidth = [UIScreen mainScreen].bounds.size.width;
     _providerToolbar = [[UIToolbar alloc] initWithFrame:CGRectMake(0, self.view.bounds.size.height - 244, self. view.bounds.size.width,
     44)];

      UIBarButtonItem *done = [[UIBarButtonItem alloc]
     initWithBarButtonSystemItem:UIBarButtonSystemItemDone target:self
     action:@selector(dismissActionSheet:)];
     _providerToolbar.items = @[[[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace
     target:nil action:nil], done];
     _providerToolbar.barStyle = UIBarStyleBlackOpaque; [self.view addSubview:_providerToolbar];

     _providerDatePicker = [[UIDatePicker alloc] initWithFrame:CGRectMake(0, self.view.bounds.size.height - 200,
     screenWidth, 200.0f)];
     _providerDatePicker.backgroundColor = [UIColor whiteColor];
     _providerDatePicker.datePickerMode = UIDatePickerModeDate;    // [_providerDatePicker setLocale:[[NSLocale alloc]
     initWithLocaleIdentifier:@"US"]];

     _providerDatePicker.date = [NSDate date];

I am using method in button action to show DatePicker but it is Comming but it show like shown in image. I want to change it to DD/MM/YY. Help me in this?enter image description here

Tushar Sharma
  • 2,839
  • 1
  • 16
  • 38
Raman Srivastava
  • 396
  • 1
  • 14

2 Answers2

1

You may check the answer here: iPhone:DatePicker dd/mm/yyyy

NSLocale *uk = [[NSLocale alloc] initWithLocaleIdentifier:@"US"];
NSCalendar *cal = [NSCalendar currentCalendar];
[cal setLocale:uk];
[myDatePicker setCalendar:cal];
Community
  • 1
  • 1
Luan Lai
  • 473
  • 2
  • 10
1

The problem is that you don't want to actually show it in US format. The US format for dates is month/day/year.

If you want English and day/month/year, you can use the British locale:

_providerDatePicker.locale = [NSLocale localeWithLocaleIdentifier:@"en_GB"];

In general it's not a good idea to tamper with locales to set a specific format. You should be using the system format because that's the one the users want to use.

Sulthan
  • 128,090
  • 22
  • 218
  • 270