I need an UIPickerView or UIDatePicker whit a specific dateFormat - ios

I need a UIDatePicker or UIPickerView with the following date format:
yyyy-MM-dd HH-mm
Do I have to create it ? or is there some pickerStyle or pickerMode that implements it?

You can do this simply by using a UIDatePicker and then set the pickerMode for it. Since, you need both Date as well as Time, all you have to do is set the mode to UIDatePickerModeDateAndTime
UIDatePicker *datePicker;
timePick.datePickerMode =UIDatePickerModeDateAndTime;
The following is provided in the Apple documentation for the above mode-
The date picker displays dates (as unified day of the week, month, and
day of the month values) plus hours, minutes, and (optionally) an
AM/PM designation. The exact order and format of these items depends
on the locale set. An example of this mode is [ Wed Nov 15 | 6 | 53 | PM ].
EDIT:
In your case, I think the only option you have is to implement two UIDatePickers, one with mode set as UIDatePickerModeDate and another with UIDatePickerModeTime. Then, you can concat them both into an NSDate.
Hope this helps!!

Related

How to change Date Format in UIDatePicker

I got stuck that I don't know how to change Date Format in UIDatePicker? As default, current dateformat in UIDatePicker is December 23 2015. What I want is I want to change 23 Dec 2015.
Any solution will be appreciated.
The displayed date format of the UIDatePicker is depending on the locale settings of the UIDatePicker.
https://developer.apple.com/library/ios/documentation/UIKit/Reference/UIDatePicker_Class/#//apple_ref/occ/instp/UIDatePicker/locale
To change it, you have to set an NSLocale, which prefers your format.

Datepicker date format issue

I am trying to select a date from DatePicker. It works properly often but when i select future date, the picker sets itself to current date(as per my code of maxdate). In this date shows current date in label but at backend object it is actually 1 day minus of current date. e.g After auto set of picker to current date, it displays in label 09-Apr-2015 but in my object(nsdate) which is want to Post to server api, it shows 2015-04-08 18:30:00 +0000. Thus my object send 8 apr to the server. Kindly reply if someone has faced this problem.
This is not a problem. The date picker is giving you correct time but only in the other time zone (Appears GMT+5:30)
When you are sending the date in your API, convert it to NSString using NSDateFormatter of the default time-zone or time-zone of your choice.
Some thing is wrong with your GMT settings.
try this code to fix:
[yourdataobject dateByAddingTimeInterval:[[NSTimeZone localTimeZone] secondsFromGMT]];
This will automatically fix your date in whatever zone your app is running in.

Is it possible to set UIDatePicker to only days (exclude hours, minutes and seconds)?

I'm trying to have a UIDatePicker to present only the date, month and year to the user. I want to avoid presenting them with the hours, minutes and seconds like it comes by default. I've tried looking for something that might help but can only find solutions that aren't explained clearly in Objective-C, however I'm coding in Swift. Any ideas? Thanks in advance!
you need to chose the mode of the date picker
#IBOutlet weak var myDatePicker: UIDatePicker!
override func viewDidLoad() {
super.viewDidLoad()
myDatePicker.datePickerMode = .date // or .Date (Swift 2.x)
}
date picker options .
Declaration SWIFT
var datePickerMode: UIDatePickerMode
Discussion The
value of this property indicates the mode of a date picker. It
determines whether the date picker allows selection of a date, a time,
both date and time, or a countdown time. The default mode is
UIDatePickerModeDateAndTime. See Date Picker Mode for a list of mode
constants.
UIDatePickerMode
The mode of the date picker.
Declaration Constants
Time
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 ].
Available in iOS 2.0 and later.
Date
The date picker 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 [ November | 15 | 2007 ].
Available in iOS 2.0 and later.
DateAndTime
The date picker displays dates (as unified day of the week, month, and day of the month values) plus hours, minutes, and (optionally) an AM/PM designation. The exact order and format of these items depends on the locale set. An example of this mode is [ Wed Nov 15 | 6 | 53 | PM ].
Available in iOS 2.0 and later.
CountDownTimer
The date picker displays hour and minute values, for example [ 1 | 53 ]. The application must set a timer to fire at the proper interval and set the date picker as the seconds tick down.
Available in iOS 2.0 and later.
If you're using storyboards just change mode to "date" in the Attributes inspector.
YourPickerView.datePickerMode=UIDatePickerModeDate;

IOS 7+ Custom DateTimePicker Time Range

I wonder if there is a way to custom a datepicker's time range?
How can I remove minute column and leave only 9 and 5 in hour column? is that possible?
Maybe you should considere to use this cocoapod:
https://www.cocoacontrols.com/controls/dvdatepickertableviewcell
or this webpage:
http://blog.deeplink.me/post/81386967477/how-to-easily-customize-uidatepicker-for-ios
and try to custom it as you want.
For UIDatepicker it is not possible to remove the minutes column or only to show 9 and 5 hour in hour column.
UIDatePickerModeDateAndTime:
The date picker displays dates (as unified day of the week, month, and day of the month values) plus hours, minutes, and (optionally) an AM/PM designation. The exact order and format of these items depends on the locale set. An example of this mode is [ Wed Nov 15 | 6 | 53 | PM ].
You need to use custom datepicker for that,you may consider to look at this link for custom picker https://github.com/mwermuth/MWDatePicker
for MWDatePicker first date were invisible but changing the font color like this [datePicker setFontColor:[UIColor blueColor]]; in viewdidLoad in MWViewController.m make them visible.And then modifying the method fillWithCalendar in MWDatePicker.m like this
- (void)fillWithCalendar{
minutes = #[#""];
hours = #[#"05",#"09"];
////others coding
}
i think would give you desired output.

DatePicker include Year

I have dataPicker in my app implemented. But it only shows month,day,hour. How could I able to add year in the date picker. Any idea?
datePicker.datePickerMode = UIDatePickerModeDate;
UIDatePickerModeDate
The date picker 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 [ November | 15 | 2007 ].
Available in iOS 2.0 and later.
Declared in UIDatePicker.h.
http://developer.apple.com/library/ios/#documentation/uikit/reference/UIDatePicker_Class/Reference/UIDatePicker.html
Also you can change from storyboard set Mode: (Refer to screenshot)
If you want to add month, date, year as well as time, add one picker that implements the dates only using (UIDatePickerModeDate) and an additional one for the time (UIDatePickerModeTime).

Resources