Free Trial

Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.

  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint
Share this Page URL

Chapter 11. Creating and Managing Table ... > One More Thing: Formatting Dates

One More Thing: Formatting Dates

Although the NSDateFormatter class has evolved a great deal from its early days and now offers highly customizable elements that can be localized for various calendars and cultures, it helps to have a quick reference on hand for the most common date and time formats. Table 11-1 provides that reference, listing the most commonly used default codes. These codes are like the ones used in Recipe 11-10 to format the results from the date picker’s date property for the midscreen label. Listing 11-1 uses the formats from Table 11-1 to create an NSString utility that converts a string into a date using a format of Month-Day-Year (for example, @"05-22-1934").

Table 11-1. Default Format Codes for the NSDateFormatter Class
Day of monthd1 to 31, no leading zeros
 dd01 to 31, uses leading zeros
MonthM L1 to 12, numeric month value, no leading zeros
 MM LL01 to 12, numeric month value, leading zeros
 MMM LLLJan to Dec, three-letter month abbreviation
 MMMM LLLLJanuary to December, full month name
Yeary uFour-digit year (e.g., 2009)
 yyTwo-digit year (e.g., 09)
Hourh K1 to 12, no leading zeros
 hh KK01 to 12, leading zeros
 H k0 to 23, 24-hour clock, no leading zeros
 HH kk00 to 23, 24-hour clock, leading zeros
Minutesm0 to 59, no leading zeros
 mm00 to 59, leading zeros
Secondss0 to 59, no leading zeros
 ss0 to 59, leading zeros
Day of Weekccc EEESun through Sat, three-letter abbreviations
 cccc EEEESunday through Saturday, full names
 c eOrdinal day of week (0–7)
 cc eeOrdinal day of week (00–07)
Week of MonthF1–5, no leading zeros
 FF01–05, leading zeros
Day of YearD1–366, no leading zeros
 DD01–366, one leading zero
 DDD001–366, two leading zeros
Week of Yearw1–52, no leading zeros
 ww01-51, one leading zero
Millisecond of DayA0–86399999, no padding
Astronomical Julian Day NumbergNumber of days since 1 January 4713 BCE
EraGBC, AD—Christian year notation
 GGGGBefore Christ, Anno Domini—Christian year notation
Quarterq Q1–4, quarter of year
 qq QQ01–04, one leading zero
 qqq QQQQ1, Q2, Q3, Q4
 qqqq QQQQ1st quarter, 2nd quarter, 3rd quarter, 4th quarter
Time ZonevTwo-letter time zone (e.g., MT)
 V zThree-letter time zone (e.g., MDT)


RFC 822 time zone offset from Greenwich Mean Time (e.g., GMT-06:00)
 vvvvTime zone name (e.g., Mountain Time)
 VVVVTime zone location (e.g., United States [Denver])
 zzzzFull time zone name (e.g., Mountain Daylight Time)
 ZGMT offset (e.g., -0600)
Other characters:


Colon, hyphen, slash


You are currently reading a PREVIEW of this book.


Get instant access to over $1 million worth of books and videos.


Start a Free 10-Day Trial

  • Safari Books Online
  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint