datePicker shows 1.January - ios

I am using Xcode and programming for ios.
I have a datePicker in my application for reservations.
You can't reserve dates that passed.
When I press on datePicker, when it opens, instead of "Today" it shows "Thu 1 Jan".
If I scroll for one day up, it will show "Fri 2 Jan".
But, if I scroll for few day in past, when it comes back to today's date it shows "Today", as it should, and everything works normal from that point.
Even if it says "Thu 1 Jan" if I save date and time, it shows correct date and time.
- (void)showDatePicker {
_orderTableView.userInteractionEnabled = NO;
_datePicker.date = _order.scheduleDate;
_datePicker.minimumDate = [NSDate date];
[UIView animateWithDuration:0.3 animations:^{
_datePickerView.frameBottom = self.view.frameBottom;
}];
}
Every suggestion is more than appreciated.
Edit1: Not sure if relevant, but minimum Date I put as Constraints is 01/01/1970 (that year New Year was on Thursday).

I was having this exact same problem and finally realized that the date I was giving the picker was not the date I thought I was giving it (01/01/0001 instead of the current date). Giving it the right date fixed the problem. Note that I am using Xamarin and C# but the concept may be the same.

Select your UIDatePicker in attribute inspector in Date choose current date.This will display your current date.

Related

How to DatePicker with Year Month day time

How to get DatePicker |Year|Day Date Month|Time Min|Second|AM PM| ?
Default DatePicker Showing its showing |Day Date Month | Min | Seconds|
Date picker is a very high level component and does not allow explicit setting of display in any way. There are properties you can play around with such as datePickerMode and locale. For your case I guess you should find a correct locale.
This is not advised though. The thing is that locale is set automatically or it should be set to whatever makes sense to user which world-wide depends on the user. If you override this functionality you will most likely confuse users.
Anyway if you can't get the result you want with date picker you will have to user a normal picker view and manage sections and rows yourself.
You can get some how close to your desired requirement by setting DatePicker's datePickerMode property
myDatePicker.datePickerMode = .dateAndTime
see the more available datepicker mode .here
UIDatePicker takes device Time format. If you have 24 hour Date format selected in your device, the UIDatePicker will not show AM/PM and show the time in 24hr. format. So you have to change the Time format of the device to 12 hour format. We can not set the time format of the UIDatePicker.

How to have this date picker mode?

The reminders app uses this date picker mode of "wed, april 20" and the hours, but in my app, I'd like to have only the "wed, april 20" format. I'm using the normal Date mode (date - month - year) right now, but as it is not showing the date's name its a bit confusing. Is this a normal mode that I can use (the reminders app mode)?
Taking the flow of the question, I also wanna ask something: to set the date picker as a text field's input view I need to create an action of the text field and use textField.inputView = datePicker
Right?
Reply to the questions you know, or both, thanks in advance!
The date format of the UIDatePicker can only be set using it's mode property and it doesn't allow a lot of flexibility, like displaying a week day. If you want to achieve this you either have to make your own date picker using a UIPickerView, or find some of the third-party components available online.
You can change datePicker mode as
[picker setDatePickerMode:UIDatePickerModeDateAndTime];

How to Change UIDatepicker Components from Day/Month/Year to Year/Month/Day

Whenever we use UIDatePicker as Date Mode. it show as
Where first we have to choose the Day/Month/Year (from left to right)
My requirement is Year/Month/Day (from left to right).
In Apple's documentation they specified that in UIDatePickerModeDate. The DatePicker displays months, days of the month, and years. The exact order of these items depends on the locale setting. An example of this mode is [ June | 18 | 2013 ]. But In device it display as DD/MM/YYYY. See UIDatePicker for more info.
So if you want to do it yourself you could create your own UIPickerView with the values you want.
It might helps you create you own UIPickerView

datePicker with maximum year current year

I am developing an iPhone app where user can save Birthdays along with other data.
For Birthday I am trying to add a UIDatePicker that shows date, month and year. for the year I want to set the picker maximum range to current year and after that an empty slot (just like the contact/phone app - add birthday option).
Is there anyway I can do that using UIDatePicker or do I have to use custom picker.
You can set the property maximumDate with current Date object. It will not allow the user to select any date beyond today. However it will not show the empty slots but grayed out slots. If user will try to select it, picker will again set with max possible date.
datePicker. maximumDate = [NSDate date];

iOS uidatepicker set time for each day

I want my iPhone app to have a date&time picker with constraints on time 10 AM to 5 PM for all future days. For example,my user should be able to select today with maximum of 5 PM or a future date with time between 10 am and 5 pm.
The minimum and maximum date properties doesnt help me with my requirement. Any possible solution? Thanks in advance :)
UIDatePicker doesn't appear to support a minimum or maximum time, only date.
You will have to either subclass UIDatePicker and create your own, or possibly alert the user when they select something out of your bounds.
A similar question was posted here: Time range on date picker for specific dates iPhone

Resources