Creating a Date Object
Working with the JavaScript Date
object is the bane of many programmers, mostly due to the need for web
pages to operate for a global audience where formats and time zones
confound even the best of plans. If you thought that the JavaScript
Date object was a headache, I don’t
have good news for you on the Cocoa Touch side of things. To perform even
simple tasks often requires navigating through multiple classes dealing
with dates, calendars, and date components—and that’s not even getting
into the formatted display of date and time data. That’s one reason why
the discussion involving dates is spread across a few sections in this
chapter.
Despite this potentially fearsome complexity, one factor that is
actually much simpler to deal with in an iOS app is obtaining a valid date
and time input from the user. The whole issue of validating text field
entries in web forms thankfully becomes a nonissue with the aid of the
UIDatePicker control, shown in Figure 9-1.

Figure 9-1. The UIDatePicker control
Adding a UIDatePicker to Workbench
If you want to try out some of the examples dealing with dates, I
recommend you add (at least temporarily) a UIDatePicker control to the Workbench app, as
well as a method that executes when a user chooses a date. Begin by
adding a little bit of code to the WorkbenchViewController class files. First, add the following method declaration to ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access