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.

UIDatePicker

Then becomes the imported know how to "read" the date set in the control:

Objective-C:
  1. / / This method works on both the simulation is on the device (SDK 2.2.1)
  2. date = dateInsert.date; NSData * date = dateInsert.date;
  3. dateFormat = [ [ NSDateFormatter alloc ] init ] ; NSDateFormatter * dateFormat = [[NSDateFormatter alloc] init];
  4. @ "yyyy-MM-dd HH:mm" ] ; [DateFormat setDateFormat: @ "yyyy-MM-dd HH: mm"];
  5. , [ dateFormat stringFromDate : date ] ) ; NSLog (@ "Date formatted:% @", [stringFromDate dateFormat: date]);

Objective-C:
  1. / / Also works on both, and Device Simulator, but when you
  2. / / Compile for the device emits a warning
  3. / / Warning: 'NSData' may not respond to '-descriptionWithCalendarFormat: timeZone: locale:'
  4. , [ 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]);

Related Post

Was this article helpful?: Per nientePocoAbbastanzaMoltoMoltissimo
Loading ... Loading ...

There are no comments for this post

Leave a comment

TAG XHTML PERMISSIONS: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> INSERTION CODE:
 <pre></pre>         // blocco generico [code][/code]       // blocco generico [as][/as]           // Actionscript [css][/css]         // CSS Style Sheet [html][/html]       // HTML [js][/js]           // Javascript [objc][/objc]       // Objective-C [php][/php]         // PHP [sql][/sql]         // SQL