date format differs when we change calender in setting - iphone

I am showing the date field in the UILabel the problem is when i change the setting of ipad
using
settings->international->calender
and change it to Buddhist from gregorian the date format differs.
How do i fix this issue so that it show the date format in gregorian only even when calender is changed?

Related

SwiftUI custom DatePicker date label format

I am looking to change the format of the selected date in the label of this SwiftUI DatePicker:
Currently, it is formatted as dd/m/yy + time, but I need it formatted with the name of the month, as dd MMMM yyyy + time (e.g. 30 June 2020 9:00am).
This is how the default calendar app displays it, which is how I want it:
I can't seem to find any methods within DatePicker to be able to do this.
Current code:
DatePicker("Starts", selection: self.$request.startDate.onChange({_ in ...}))
Because I assume you want to use the DatePicker within a Form, I have to say that this is not possible. Because DatePicker doesn't give you access to the actual date Label.
If you use it outside a form you could reference to your date and format it with DateFormatter as you like it to be.

Set UIDatePicker text color for dates outside of date range swift

I am playing with a UIDatePicker in my project and I have decided to change the text color to white with
self.datePicker.setValue(UIColor.white, forKey: "textColor")
I also have a minimum date set to today's date. The issue I am having is that the date and time text outside of my minimum date is still grey making it hard to see on my screen. I have been browsing the documentation and am not able to find a list of what key value pairs are available to the class in order to fix this. Thanks.

how to change my date picker show in only month,date ,year, and time

The default UIDatePicker shows both the date and time. I need to show only the month, day, year and time like this
How can I change the date picker to this?
Well First off I suggest reading through the UIDatePicker documentation. Here are the Date Picker Modes:
Date Picker Mode
The mode of the date picker.
typedef enum {
UIDatePickerModeTime,
UIDatePickerModeDate,
UIDatePickerModeDateAndTime,
UIDatePickerModeCountDownTimer
} UIDatePickerMode;
If you cannot find what you need there. Then you can create your own by using a UIPickerView.

How to retrict date on UIDatePickerView?

hi guys can any body help me to figure out that how i can restrict the minimum date in UIDatePickerView? i tried to set property minumumDate from xib file but it is not working, even i set the the mode like this
[datePicker setDatePickerMode:UIDatePickerModeCountDownTimer];
but still it is not working. what i want to do is that user cannot scroll down from a specific date. example: if restricted date is 21.11.2011 then user should not scroll it to less then this date so please help me to figure it out
Thanx in advance
I think you would want to set the mode to 'UIDatePickerDate', as 'UIDatePickerCountDownTimer' is meant to display a time. Have you tried:
[datePicker setDatePickerMode:UIDatePickerModeDate];
[datePicker setMinimumDate:minDate];
minDate would be an NSDate with the restricted date. For info on how to initialize this date, see here in the Apple documentation. Especially the part about date components.

Add AM/PM to datepicker?

My UIDatePicker is set to UIDatePickerModeTime but on the apple documentation it says The date picker displays hours, minutes, and (optionally) an AM/PM designation. The exact items shown and their order depend upon the locale set. An example of this mode is [ 6 | 53 | PM ].. How do i add AM/PM because on my device, those aren't options and it instead uses a 24 hour clock?
This will depend on the settings of the user. If you go to Settings -> General -> Date & Time. there is a "24-Hour" time switch, and based on that users will have the AM/PM indicator on your picker.
Unfortunately UIDatePicker doesn't have an option for that; it always respects the device option of 12-hour or 24-hour time.
If you must have an AM/PM component you may have to go with a custom UIPickerView instead, and build an NSDate out of its components manually.
This thread is somewhat old, but maybe this will be useful to someone else...
As written in the original question, the picker will respect the locale. So, if you what to overrule the system-settings you can set the desired locale on the picker like this:
picker.locale = Locale.init(identifier: "en")
Two things to check,
UIDatePicker has mode which needs to be either set to .time or .dateAndTime in order to support AM/PM format.
set locale to a locale that supports AM/PM, eg "en_US_POSIX", if your locale is set to current, it will read system locale.