# NSDateFormatter class reference

richard@brainstorm.co.uk
Generated at 2025-02-13 06:02:40 +0000
1998 Free Software Foundation, Inc.
Software documentation for the NSDateFormatter class
Foundation/NSDateFormatter.h
NSCoding
NSCopying

Class for generating text representations of NSDate s and NSCalendarDate s, and for converting strings into instances of these objects. Note that NSDate and NSCalendarDatedo contain some string conversion methods, but using this class provides more control over conversion.

See the NSFormatterdocumentation for description of the basic methods for formatting and parsing that are available.

The basic format of a format string uses "%" codes to represent components of the date. Thus, for example, `@"%b %d, %Y"` specifies strings similar to "June 18, 1991". The full list of codes is as follows:

%%
a '%' character
%a
abbreviated weekday name
%A
full weekday name
%b
abbreviated month name
%B
full month name
%c
shorthand for "%X %x", the locale format for date and time
%d
day of the month as a decimal number (01-31)
%e
same as %d but does not print the leading 0 for days 1 through 9 (unlike "strftime()", does not print a leading space)
%F
milliseconds as a decimal number (000-999)
%H
hour based on a 24-hour clock as a decimal number (00-23)
%I
hour based on a 12-hour clock as a decimal number (01-12)
%j
day of the year as a decimal number (001-366)
%m
month as a decimal number (01-12)
%M
minute as a decimal number (00-59)
%p
AM/PM designation for the locale
%S
second as a decimal number (00-59)
%w
weekday as a decimal number (0-6), where Sunday is 0
%x
date using the date representation for the locale, including the time zone (produces different results from "strftime()")
%X
time using the time representation for the locale (produces different results from "strftime()")
%y
year without century (00-99)
%Y
year with century (such as 1990)
%Z
time zone name (such as Pacific Daylight Time; produces different results from "strftime()")
%z
time zone offset in hours and minutes from GMT (HHMM)
Warning the underscore at the start of the name of this instance variable indicates that, even though it is not technically private, it is intended for internal use within the package, and you should not use the variable in other code.
Warning the underscore at the start of the name of this instance variable indicates that, even though it is not technically private, it is intended for internal use within the package, and you should not use the variable in other code.
dateFormatFromTemplate:
aTemplate
options:
opts
locale:
locale
Description forthcoming.
defaultFormatterBehavior
Description forthcoming.
localizedStringFromDate:
date
dateStyle:
dateStyle
timeStyle:
timeStyle
Description forthcoming.
setDefaultFormatterBehavior:
behavior
Description forthcoming.
AMSymbol
Description forthcoming.
PMSymbol
Description forthcoming.
allowsNaturalLanguage
Returns whether initialized to support natural language formatting. If `YES`, string-to-object conversion will attempt to process strings as natural language dates, such as "yesterday", or "first Tuesday of next month" if straight format-based conversion fails.
calendar
Description forthcoming.
dateFormat
Returns format string initialized with, specifying how dates are formatted, for object-to-string conversion, and how they are parsed, for string-to-object conversion. For example, `@"%b %d, %Y"` specifies strings similar to "June 18, 1991".
dateFromString:
string
Description forthcoming.
dateStyle
Description forthcoming.
defaultDate
Description forthcoming.
doesRelativeDateFormatting
Description forthcoming.
eraSymbols
Description forthcoming.
formatterBehavior
Description forthcoming.
generatesCalendarDates
Description forthcoming.
getObjectValue:
obj
forString:
string
range:
range
error:
error
Description forthcoming.
gregorianStartDate
Description forthcoming.
initWithDateFormat:
format
allowNaturalLanguage:
flag
Initialize with given specifier string format. See class description for how to specify a format string. If flag is `YES`, string-to-object conversion will attempt to process strings as natural language dates, such as "yesterday", or "first Tuesday of next month" if straight format-based conversion fails.
isLenient
Description forthcoming.
locale
Description forthcoming.
longEraSymbols
Description forthcoming.
monthSymbols
Description forthcoming.
quarterSymbols
Description forthcoming.
setAMSymbol:
string
Description forthcoming.
setCalendar:
calendar
Description forthcoming.
setDateFormat:
string
Description forthcoming.
setDateStyle:
style
Description forthcoming.
setDefaultDate:
date
Description forthcoming.
setDoesRelativeDateFormatting:
flag
Description forthcoming.
setEraSymbols:
array
Description forthcoming.
setFormatterBehavior:
behavior
Description forthcoming.
setGeneratesCalendarDates:
flag
Description forthcoming.
setGregorianStartDate:
date
Description forthcoming.
setLenient:
flag
Description forthcoming.
setLocale:
locale
Description forthcoming.
setLongEraSymbols:
array
Description forthcoming.
setMonthSymbols:
array
Description forthcoming.
setPMSymbol:
string
Description forthcoming.
setQuarterSymbols:
array
Description forthcoming.
setShortMonthSymbols:
array
Description forthcoming.
setShortQuarterSymbols:
array
Description forthcoming.
setShortStandaloneMonthSymbols:
array
Description forthcoming.
setShortStandaloneQuarterSymbols:
array
Description forthcoming.
setShortStandaloneWeekdaySymbols:
array
Description forthcoming.
setShortWeekdaySymbols:
array
Description forthcoming.
setStandaloneMonthSymbols:
array
Description forthcoming.
setStandaloneQuarterSymbols:
array
Description forthcoming.
setStandaloneWeekdaySymbols:
array
Description forthcoming.
setTimeStyle:
style
Description forthcoming.
setTimeZone:
tz
Description forthcoming.
setTwoDigitStartDate:
date
Description forthcoming.
setVeryShortMonthSymbols:
array
Description forthcoming.
setVeryShortStandaloneMonthSymbols:
array
Description forthcoming.
setVeryShortStandaloneWeekdaySymbols:
array
Description forthcoming.
setVeryShortWeekdaySymbols:
array
Description forthcoming.
setWeekdaySymbols:
array
Description forthcoming.
shortMonthSymbols
Description forthcoming.
shortQuarterSymbols
Description forthcoming.
shortStandaloneMonthSymbols
Description forthcoming.
shortStandaloneQuarterSymbols
Description forthcoming.
shortStandaloneWeekdaySymbols
Description forthcoming.
shortWeekdaySymbols
Description forthcoming.
standaloneMonthSymbols
Description forthcoming.
standaloneQuarterSymbols
Description forthcoming.
standaloneWeekdaySymbols
Description forthcoming.
stringFromDate:
date
Description forthcoming.
timeStyle
Description forthcoming.
timeZone
Description forthcoming.
twoDigitStartDate
Description forthcoming.
veryShortMonthSymbols
Description forthcoming.
veryShortStandaloneMonthSymbols
Description forthcoming.
veryShortStandaloneWeekdaySymbols
Description forthcoming.
veryShortWeekdaySymbols
Description forthcoming.
weekdaySymbols
Description forthcoming.