0

I had created a Date picker controller and want to set the timeinterval to 12hrs pragmatically.

But i cant do that, i think this is very simple problem but please help me for this.

Thank you in advance.

RJ168
  • 1,006
  • 2
  • 12
  • 22

2 Answers2

0

In Swift 4.X:

let detailsTimeFormatter = DateFormatter()
detailsTimeFormatter.timeStyle = .short
detailsTimeFormatter.dateFormat = "HH:mm"
print(detailsTimeFormatter.string(from: Date()).lowercased())

Assign this time string date to the picker view.

yo2bh
  • 1,356
  • 1
  • 14
  • 26
0

Try this:

NSDateFormatter *detailsTimeFormatter = [[NSDateFormatter alloc] init];
    [detailsTimeFormatter setTimeStyle:NSDateFormatterShortStyle];
    NSLog(@"%@",[[detailsTimeFormatter stringFromDate:[NSDate date]] lowercaseString]); // this will return you the time with am/pm
relower
  • 1,293
  • 1
  • 10
  • 20
  • I want to set the 12 hr timezone to date picker controller. So if you know give me that property. Thank you. – RJ168 Nov 16 '11 at 10:05
  • you need to use NSDateFormatter: `[datePickerFormat setDateFormat:@"HH:mm"];` http://stackoverflow.com/questions/4360402/uidatepicker-return-value-in-24-hour-format look the guide: http://unicode.org/reports/tr35/tr35-6.html#Date_Format_Patterns – relower Nov 16 '11 at 10:18
  • with this we can get the string or date in that format but i want to apply the 12hr date format to date picker controller. – RJ168 Nov 16 '11 at 10:27
  • can you look at this topic, it may can help you : http://stackoverflow.com/questions/2894161/uidatepicker-problem-localizing/2918507#2918507 – relower Nov 16 '11 at 10:46
  • Hey thank you it is really good but tell me how to set the time zone... because with this it sets the english language and calender but not the time format to 12hr's ... Thank you. – RJ168 Nov 18 '11 at 10:40