swift xcode UIDatepicker - ios

How do I get data picker to display and select the year also.
Currently I see the following but what I need is Year Mon Day HH MM

.datePickerMode = .date or .datePickerMode = .dateAndTime
both are dependant on locale... so different countries will see different potentially undesirable formats.
Swift Accessing year from UIDatePicker
You can customise UIPickerView though if you need to...
Can i customize UIDatePicker?

Related

How to set date formate for UIDatePicker View

How to set date formate to the UIDatePickerView for month MMM using locale can we achieve it?
Is there away to set three char of month to UIDatePickerView
No, you can't set a specific format on a date picker. You can set the locale (which defaults to the user's current locale) which affects the format.
If you truly want a date picker with a specific format (bad idea because it will likely confuse users), you will need to create your custom date picker using UIPickerView.

ios:Date picker with short format

I want a date picker like this one, with the month name in short format:
But this is what I get:
This has the full month name, which is not what I want.
I set date picker mode like this:
mydatepicker.datepickermode = datepickermode.date
but it's not working.
Embedded datePicker is not very flexible to adjust. The way to solve your issue is to create your own picker by using UIPickerView. You need to create a picker with 3 components and configure it depending on your wishes. But this way is a little bit annoying, because you need to keep in mind, that every month has it's own number of days. And don't forget also about 29th of February.

How can we change the Date Picker Format When the toggle set to All Day

Just Making Calendar app which i have the same requirement as IOS calendar. In that All Day toggle Changes To Different Date Formatting And DatePicker Style is also different. How can i deal with that?.
Use NSDateFormatter and when user change the toggle update format of date using Date formatter and load new format in Picker.
you have option to create another picker otherwise you have to define condition on the picker delegate to show the new date format or your required format .
when you first time open the picker than the content would load on to the picker may be there is a chance when you pass the command to change format than the picker is still showing previous content than you need to reload the picker content to update the picker content value and to show the updated format type content.
may this could help you.

Datepicker maximumDate stuck on yesterday day during early time of the current day

I have a date picker that is set to not allow users to pick future dates. It's maximum date is set for the current time on viewDidLoad.
dateDatePicker.maximumDate = NSDate()
But I've been noticing a bug. Today until midday the maximum date was yesterdays date. But now, after midday it is showing todays date.
The way I implemented it: The date picker is shown and hidden with alpha when user wants to use it. So I am setting the maximum date not every time the picker is shown but once it loads the view it is in.
So I am not sure if this is a bug?
Is it has to do with timezones?
Or has to do with the fact that I am only calling dateDatePicker.maximumDate once when they view loaded and that could have happened days ago?
Or if I should reset the maximumDate every time I show the datePicker?
Yes, you should almost certainly set the maximum date each time you show the date picker.
If you set the maximum date on a previous day and then never updated it nor closed the view controller the it wouldn't change.
Set it in viewWillAppear, not viewDidLoad.
If that doesn't work, use NSCalendar and NSDateComponents to build an NSDate which is 23:59 on the current date (fetch the MM/DD/YYYY from the current date as date components, then manually set the time to 23:59. That should work.

UIDatePicker customize available time intervals

Is it possible to set in UIDatePicker, date/time frames selectively? for example: show only Mondays from 8am to 4pm ?
Unfortunately, you cannot do this with standard UIDatePicker. Instead you should build your own custom date picker based on UIPickerView.

Resources