Very short snippet: format a date for a control UIDatePicker
Friday, November 6, 2009 Control UIDatePicker is perhaps the most beautiful graphics control this on an Apple iPhone. Besides the beauty is also easy to use, extremely versatile and used in many situations.

Then becomes the imported know how to "read" the date set in the control:
- / / This method works on both the simulation is on the device (SDK 2.2.1)
- dateFormat = [ [ NSDateFormatter alloc ] init ] ; NSDateFormatter * dateFormat = [[NSDateFormatter alloc] init];
- @ "yyyy-MM-dd HH:mm" ] ; [DateFormat setDateFormat: @ "yyyy-MM-dd HH: mm"];
- , [ dateFormat stringFromDate : date ] ) ; NSLog (@ "Date formatted:% @", [stringFromDate dateFormat: date]);
- / / Also works on both, and Device Simulator, but when you
- / / Compile for the device emits a warning
- / / Warning: 'NSData' may not respond to '-descriptionWithCalendarFormat: timeZone: locale:'
- , [ dateInsert.date descriptionWithCalendarFormat : @ "%Y%m%d %H:%M" timeZone : nil locale : nil ] ) ; NSLog (@ "Date formatted:% @", [dateInsert.date descriptionWithCalendarFormat: @ "% Y% m% d% H:% M" timeZone: nil local: nil]);













There are no comments for this post
Leave a comment