NSDateFormatter Class Reference
| Inherits from | |
| Conforms to | |
| Framework | /System/Library/Frameworks/Foundation.framework |
| Availability | Available in OS X v10.0 and later. |
| Companion guide | |
| Declared in | NSDateFormatter.h |
Overview
Instances of NSDateFormatter create string representations of NSDate objects, and convert textual representations of dates and times into NSDate objects. You can express the representation of dates and times flexibly using pre-set format styles or custom format strings.
There are many attributes you can get and set on a 10.4-style date formatter, including the locale, time zone, calendar, format string, and the various textual strings like the month names. You are encouraged, however, not to change individual settings. Instead you should accept the default settings established on initialization and specify the format using setDateStyle:, setTimeStyle:, and appropriate style constants (see NSDateFormatterStyle—these are styles that the user can configure in the International preferences panel in System Preferences).
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init]; |
[dateFormatter setTimeStyle:NSDateFormatterNoStyle]; |
[dateFormatter setDateStyle:NSDateFormatterMediumStyle]; |
NSDate *date = [NSDate dateWithTimeIntervalSinceReferenceDate:118800]; |
NSLocale *usLocale = [[NSLocale alloc] initWithLocaleIdentifier:@"en_US"]; |
[dateFormatter setLocale:usLocale]; |
NSLog(@"Date for locale %@: %@", |
[[dateFormatter locale] localeIdentifier], [dateFormatter stringFromDate:date]); |
// Output: |
// Date for locale en_US: Jan 2, 2001 |
NSLocale *frLocale = [[NSLocale alloc] initWithLocaleIdentifier:@"fr_FR"]; |
[dateFormatter setLocale:frLocale]; |
NSLog(@"Date for locale %@: %@", |
[[dateFormatter locale] localeIdentifier], [dateFormatter stringFromDate:date]); |
// Output: |
// Date for locale fr_FR: 2 janv. 2001 |
Note that although setting a format string (setDateFormat:) in principle specifies an exact format, in practice it may nevertheless also be overridden by a user’s preferences—see Data Formatting Guide for more details.
Formatter Behaviors and OS Versions
With OS X v10.4 and later, NSDateFormatter has two modes of operation (or behaviors). See Data Formatting Guide for a full description of the old and new behaviors.
By default, in OS X v10.4 instances of NSDateFormatter have the same behavior as they did on OS X versions 10.0 to 10.3. In OS X v10.5 and later, NSDateFormatter defaults to the 10.4+ behavior. However, if you initialize a formatter using initWithDateFormat:allowNaturalLanguage:, you are (for backwards compatibility reasons) creating an “old-style” date formatter. To use the new behavior, you initialize the formatter with init. If necessary, you can set the default class behavior using setDefaultFormatterBehavior:, or you can set the behavior for an instance using setFormatterBehavior: message with the argument NSDateFormatterBehavior10_4.
Tasks
Initializing a Date Formatter
Converting Objects
-
– dateFromString: -
– stringFromDate: -
+ localizedStringFromDate:dateStyle:timeStyle: -
– getObjectValue:forString:range:error: -
– generatesCalendarDates -
– setGeneratesCalendarDates:
Managing Formats and Styles
-
– dateFormat -
– setDateFormat: -
– dateStyle -
– setDateStyle: -
– timeStyle -
– setTimeStyle: -
+ dateFormatFromTemplate:options:locale:
Managing Attributes
-
– calendar -
– setCalendar: -
– defaultDate -
– setDefaultDate: -
– locale -
– setLocale: -
– timeZone -
– setTimeZone: -
– twoDigitStartDate -
– setTwoDigitStartDate: -
– gregorianStartDate -
– setGregorianStartDate:
Managing Behavior Version
-
– formatterBehavior -
– setFormatterBehavior: -
+ defaultFormatterBehavior -
+ setDefaultFormatterBehavior:
Managing Natural Language Support
-
– allowsNaturalLanguage -
– isLenient -
– setLenient: -
– doesRelativeDateFormatting -
– setDoesRelativeDateFormatting:
Managing AM and PM Symbols
Managing Weekday Symbols
-
– weekdaySymbols -
– setWeekdaySymbols: -
– shortWeekdaySymbols -
– setShortWeekdaySymbols: -
– veryShortWeekdaySymbols -
– setVeryShortWeekdaySymbols: -
– standaloneWeekdaySymbols -
– setStandaloneWeekdaySymbols: -
– shortStandaloneWeekdaySymbols -
– setShortStandaloneWeekdaySymbols: -
– veryShortStandaloneWeekdaySymbols -
– setVeryShortStandaloneWeekdaySymbols:
Managing Month Symbols
-
– monthSymbols -
– setMonthSymbols: -
– shortMonthSymbols -
– setShortMonthSymbols: -
– veryShortMonthSymbols -
– setVeryShortMonthSymbols: -
– standaloneMonthSymbols -
– setStandaloneMonthSymbols: -
– shortStandaloneMonthSymbols -
– setShortStandaloneMonthSymbols: -
– veryShortStandaloneMonthSymbols -
– setVeryShortStandaloneMonthSymbols:
Managing Quarter Symbols
-
– quarterSymbols -
– setQuarterSymbols: -
– shortQuarterSymbols -
– setShortQuarterSymbols: -
– standaloneQuarterSymbols -
– setStandaloneQuarterSymbols: -
– shortStandaloneQuarterSymbols -
– setShortStandaloneQuarterSymbols:
Managing Era Symbols
Class Methods
dateFormatFromTemplate:options:locale:
Returns a localized date format string representing the given date format components arranged appropriately for the specified locale.
Parameters
- template
A string containing date format patterns (such as “MM” or “h”).
For full details, see Date and Time Programming Guide.
- opts
No options are currently defined—pass
0.- locale
The locale for which the template is required.
Return Value
A localized date format string representing the date format components given in template, arranged appropriately for the locale specified by locale.
The returned string may not contain exactly those components given in template, but may—for example—have locale-specific adjustments applied.
Discussion
Different locales have different conventions for the ordering of date components. You use this method to get an appropriate format string for a given set of components for a specified locale (typically you use the current locale—see currentLocale).
The following example shows the difference between the date formats for British and American English:
NSLocale *usLocale = [[NSLocale alloc] initWithLocaleIdentifier:@"en_US"]; |
NSLocale *gbLocale = [[NSLocale alloc] initWithLocaleIdentifier:@"en_GB"]; |
NSString *dateFormat; |
NSString *dateComponents = @"yMMMMd"; |
dateFormat = [NSDateFormatter dateFormatFromTemplate:dateComponents options:0 locale:usLocale]; |
NSLog(@"Date format for %@: %@", |
[usLocale displayNameForKey:NSLocaleIdentifier value:[usLocale localeIdentifier]], dateFormat); |
dateFormat = [NSDateFormatter dateFormatFromTemplate:dateComponents options:0 locale:gbLocale]; |
NSLog(@"Date format for %@: %@", |
[gbLocale displayNameForKey:NSLocaleIdentifier value:[gbLocale localeIdentifier]], dateFormat); |
// Output: |
// Date format for English (United States): MMMM d, y |
// Date format for English (United Kingdom): d MMMM y |
Availability
- Available in OS X v10.6 and later.
Declared In
NSDateFormatter.hdefaultFormatterBehavior
Returns the default formatting behavior for instances of the class.
Return Value
The default formatting behavior for instances of the class. For possible values, see NSDateFormatterBehavior.
Discussion
For iOS and for OS X applications linked against OS X v10.5 and later, the default is NSDateFormatterBehavior10_4.
Availability
- Available in OS X v10.4 and later.
Declared In
NSDateFormatter.hlocalizedStringFromDate:dateStyle:timeStyle:
Returns string representation of a given date formatted for the current locale using the specified date and time styles.
Parameters
- date
A date.
- dateStyle
A format style for the date. For possible values, see
NSDateFormatterStyle.- timeStyle
A format style for the time. For possible values, see
NSDateFormatterStyle.
Return Value
A localized string representation of date using the specified date and time styles
Discussion
This method uses a date formatter configured with the current default settings. The returned string is the same as if you configured and used a date formatter as shown in the following example:
NSDateFormatter *formatter = [[NSDateFormatter alloc] init]; |
[formatter setFormatterBehavior:NSDateFormatterBehavior10_4]; |
[formatter setDateStyle:dateStyle]; |
[formatter setTimeStyle:timeStyle]; |
NSString *result = [formatter stringForObjectValue:date]; |
Availability
- Available in OS X v10.6 and later.
See Also
Declared In
NSDateFormatter.hsetDefaultFormatterBehavior:
Sets the default formatting behavior for instances of the class.
Parameters
- behavior
The default formatting behavior for instances of the class. For possible values, see NSDateFormatterBehavior.
Availability
- Available in OS X v10.4 and later.
Declared In
NSDateFormatter.hInstance Methods
allowsNaturalLanguage
Returns a Boolean value that indicates whether the receiver attempts to process dates entered as a vernacular string.
Return Value
YES if the receiver attempts to process dates entered as a vernacular string (“today,” “next week,” “dinner time,” and so on), otherwise NO.
Discussion
Natural-language processing supports only a limited set of colloquial phrases, primarily in English. It may give unexpected results, and its use is strongly discouraged.
Special Considerations
This method is for use with formatters using NSDateFormatterBehavior10_0 behavior.
Availability
- Available in OS X v10.0 and later.
See Also
Declared In
NSDateFormatter.hAMSymbol
Returns the AM symbol for the receiver.
Return Value
The AM symbol for the receiver.
Availability
- Available in OS X v10.4 and later.
See Also
Declared In
NSDateFormatter.hcalendar
Returns the calendar for the receiver.
Return Value
The calendar for the receiver.
Availability
- Available in OS X v10.4 and later.
See Also
Declared In
NSDateFormatter.hdateFormat
Returns the date format string used by the receiver.
Return Value
The date format string used by the receiver.
Discussion
See Data Formatting Guide for a list of the conversion specifiers permitted in date format strings.
Availability
- Available in OS X v10.0 and later.
See Also
Declared In
NSDateFormatter.hdateFromString:
Returns a date representation of a given string interpreted using the receiver’s current settings.
Parameters
- string
The string to parse.
Return Value
A date representation of string interpreted using the receiver’s current settings.
Availability
- Available in OS X v10.4 and later.
Declared In
NSDateFormatter.hdateStyle
Returns the date style of the receiver.
Return Value
The date style of the receiver. For possible values, see NSDateFormatterStyle.
Availability
- Available in OS X v10.4 and later.
See Also
Declared In
NSDateFormatter.hdefaultDate
Returns the default date for the receiver.
Return Value
The default date for the receiver.
Discussion
The default default date is nil.
Availability
- Available in OS X v10.4 and later.
See Also
Declared In
NSDateFormatter.hdoesRelativeDateFormatting
Returns a Boolean value that indicates whether the receiver uses phrases such as “today” and “tomorrow” for the date component.
Return Value
YES if the receiver uses relative date formatting, otherwise NO.
Discussion
For a full discussion, see setDoesRelativeDateFormatting:.
Availability
- Available in OS X v10.6 and later.
See Also
Declared In
NSDateFormatter.heraSymbols
Returns the era symbols for the receiver.
Return Value
An array containing NSString objects representing the era symbols for the receiver (for example, {“B.C.E.”, “C.E.”}).
Availability
- Available in OS X v10.4 and later.
See Also
Declared In
NSDateFormatter.hformatterBehavior
Returns the formatter behavior for the receiver.
Return Value
The formatter behavior for the receiver. For possible values, see NSDateFormatterBehavior.
Availability
- Available in OS X v10.4 and later.
Declared In
NSDateFormatter.hgeneratesCalendarDates
You should not use this method.
Return Value
YES if the receiver generates calendar dates, otherwise NO.
Discussion
NSCalendarDate is no longer supported; you should not use this method.
Availability
- Available in OS X v10.4 and later.
Declared In
NSDateFormatter.hgetObjectValue:forString:range:error:
Returns by reference a date representation of a given string and the range of the string used, and returns a Boolean value that indicates whether the string could be parsed.
Parameters
- obj
If the receiver is able to parse string, upon return contains a date representation of string.
- string
The string to parse.
- rangep
If the receiver is able to parse string, upon return contains the range of string used to create the date.
- error
If the receiver is unable to create a date by parsing string, upon return contains an NSError object that describes the problem.
Return Value
YES if the receiver can create a date by parsing string, otherwise NO.
Availability
- Available in OS X v10.4 and later.
See Also
Declared In
NSDateFormatter.hgregorianStartDate
Returns the start date of the Gregorian calendar for the receiver.
Return Value
The start date of the Gregorian calendar for the receiver.
Availability
- Available in OS X v10.5 and later.
See Also
Declared In
NSDateFormatter.hinitWithDateFormat:allowNaturalLanguage:
Initializes and returns an NSDateFormatter instance that uses the OS X v10.0 formatting behavior and the given date format string in its conversions.
Parameters
- format
The format for the receiver. See Data Formatting Guide for a list of conversion specifiers permitted in date format strings.
- flag
A flag that specifies whether the receiver should process dates entered as expressions in the vernacular (for example, "tomorrow")—
YESmeans that it should.
Return Value
An initialized NSDateFormatter instance that uses format in its conversions and that uses the OS X v10.0 formatting behavior.
Discussion
NSDateFormatter attempts natural-language processing only after it fails to interpret an entered string according to format. Natural-language processing supports only a limited set of colloquial phrases, primarily in English. It may give unexpected results, and its use is strongly discouraged.
The following example creates a date formatter with the format string (for example) “Mar 15 1994” and then associates the formatter with the cells of a form (contactsForm):
NSDateFormatter *dateFormat = [[NSDateFormatter alloc] |
initWithDateFormat:@"%b %d %Y" allowNaturalLanguage:NO]; |
[[contactsForm cells] makeObjectsPerformSelector:@selector(setFormatter:) |
withObject:dateFormat]; |
Special Considerations
You cannot use this method to initialize a formatter with the OS X v10.4 formatting behavior, you must use init.
Availability
- Available in OS X v10.0 and later.
See Also
Declared In
NSDateFormatter.hisLenient
Returns a Boolean value that indicates whether the receiver uses heuristics when parsing a string.
Return Value
YES if the receiver has been set to use heuristics when parsing a string to guess at the date which is intended, otherwise NO.
Availability
- Available in OS X v10.4 and later.
See Also
Declared In
NSDateFormatter.hlocale
Returns the locale for the receiver.
Return Value
The locale for the receiver.
Availability
- Available in OS X v10.4 and later.
See Also
Declared In
NSDateFormatter.hlongEraSymbols
Returns the long era symbols for the receiver
Return Value
An array containing NSString objects representing the era symbols for the receiver (for example, {“Before Common Era”, “Common Era”}).
Availability
- Available in OS X v10.5 and later.
See Also
Declared In
NSDateFormatter.hmonthSymbols
Returns the month symbols for the receiver.
Return Value
An array of NSString objects that specify the month symbols for the receiver.
Availability
- Available in OS X v10.4 and later.
See Also
Declared In
NSDateFormatter.hPMSymbol
Returns the PM symbol for the receiver.
Return Value
The PM symbol for the receiver.
Availability
- Available in OS X v10.4 and later.
See Also
Declared In
NSDateFormatter.hquarterSymbols
Returns the quarter symbols for the receiver.
Return Value
An array containing NSString objects representing the quarter symbols for the receiver.
Availability
- Available in OS X v10.5 and later.
See Also
Declared In
NSDateFormatter.hsetAMSymbol:
Sets the AM symbol for the receiver.
Parameters
- string
The AM symbol for the receiver.
Availability
- Available in OS X v10.4 and later.
See Also
Declared In
NSDateFormatter.hsetCalendar:
Sets the calendar for the receiver.
Parameters
- calendar
The calendar for the receiver.
Availability
- Available in OS X v10.4 and later.
See Also
Declared In
NSDateFormatter.hsetDateFormat:
Sets the date format for the receiver.
Parameters
- string
The date format for the receiver. See Data Formatting Guide for a list of the conversion specifiers permitted in date format strings.
Availability
- Available in OS X v10.4 and later.
See Also
Declared In
NSDateFormatter.hsetDateStyle:
Sets the date style of the receiver.
Parameters
- style
The date style of the receiver. For possible values, see NSDateFormatterStyle.
Availability
- Available in OS X v10.4 and later.
See Also
Declared In
NSDateFormatter.hsetDefaultDate:
Sets the default date for the receiver.
Parameters
- date
The default date for the receiver.
Availability
- Available in OS X v10.4 and later.
See Also
Declared In
NSDateFormatter.hsetDoesRelativeDateFormatting:
Specifies whether the receiver uses phrases such as “today” and “tomorrow” for the date component.
Parameters
- b
YESto specify that the receiver should use relative date formatting, otherwiseNO.
Discussion
If a date formatter uses relative date formatting, where possible it replaces the date component of its output with a phrase—such as “today” or “tomorrow”—that indicates a relative date. The available phrases depend on the locale for the date formatter; whereas, for dates in the future, English may only allow “tomorrow,” French may allow “the day after the day after tomorrow,” as illustrated in the following example.
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init]; |
[dateFormatter setTimeStyle:NSDateFormatterNoStyle]; |
[dateFormatter setDateStyle:NSDateFormatterMediumStyle]; |
NSLocale *frLocale = [[NSLocale alloc] initWithLocaleIdentifier:@"fr_FR"]; |
[dateFormatter setLocale:frLocale]; |
[dateFormatter setDoesRelativeDateFormatting:YES]; |
NSDate *date = [NSDate dateWithTimeIntervalSinceNow:60*60*24*3]; |
NSString *dateString = [dateFormatter stringFromDate:date]; |
NSLog(@"dateString: %@", dateString); |
// Output |
// dateString: après-après-demain |
Availability
- Available in OS X v10.6 and later.
See Also
Declared In
NSDateFormatter.hsetEraSymbols:
Sets the era symbols for the receiver.
Parameters
- array
An array containing
NSStringobjects representing the era symbols for the receiver (for example, {“B.C.E.”, “C.E.”}).
Availability
- Available in OS X v10.4 and later.
See Also
Declared In
NSDateFormatter.hsetFormatterBehavior:
Sets the formatter behavior for the receiver.
Parameters
- behavior
The formatter behavior for the receiver. For possible values, see
NSDateFormatterBehavior.
Availability
- Available in OS X v10.4 and later.
Declared In
NSDateFormatter.hsetGeneratesCalendarDates:
You should not use this method.
Parameters
- b
A Boolean value that specifies whether the receiver generates calendar dates.
Discussion
NSCalendarDate is no longer supported; you should not use this method.
Availability
- Available in OS X v10.4 and later.
Declared In
NSDateFormatter.hsetGregorianStartDate:
Sets the start date of the Gregorian calendar for the receiver.
Parameters
- date
The start date of the Gregorian calendar for the receiver.
Availability
- Available in OS X v10.5 and later.
See Also
Declared In
NSDateFormatter.hsetLenient:
Sets whether the receiver uses heuristics when parsing a string.
Parameters
- b
YESto use heuristics when parsing a string to guess at the date which is intended, otherwiseNO.
Discussion
If a formatter is set to be lenient, when parsing a string it uses heuristics to guess at the date which is intended. As with any guessing, it may get the result date wrong (that is, a date other than that which was intended).
Availability
- Available in OS X v10.4 and later.
See Also
Declared In
NSDateFormatter.hsetLocale:
Sets the locale for the receiver.
Parameters
- locale
The locale for the receiver.
Availability
- Available in OS X v10.4 and later.
See Also
Declared In
NSDateFormatter.hsetLongEraSymbols:
Sets the long era symbols for the receiver.
Parameters
- array
An array containing
NSStringobjects representing the era symbols for the receiver (for example, {“Before Common Era”, “Common Era”}).
Availability
- Available in OS X v10.5 and later.
See Also
Declared In
NSDateFormatter.hsetMonthSymbols:
Sets the month symbols for the receiver.
Parameters
- array
An array of
NSStringobjects that specify the month symbols for the receiver.
Availability
- Available in OS X v10.4 and later.
See Also
Declared In
NSDateFormatter.hsetPMSymbol:
Sets the PM symbol for the receiver.
Parameters
- string
The PM symbol for the receiver.
Availability
- Available in OS X v10.4 and later.
See Also
Declared In
NSDateFormatter.hsetQuarterSymbols:
Sets the quarter symbols for the receiver.
Parameters
- array
An array of
NSStringobjects that specify the quarter symbols for the receiver.
Availability
- Available in OS X v10.5 and later.
See Also
Declared In
NSDateFormatter.hsetShortMonthSymbols:
Sets the short month symbols for the receiver.
Parameters
- array
An array of
NSStringobjects that specify the short month symbols for the receiver.
Availability
- Available in OS X v10.4 and later.
See Also
Declared In
NSDateFormatter.hsetShortQuarterSymbols:
Sets the short quarter symbols for the receiver.
Parameters
- array
An array of
NSStringobjects that specify the short quarter symbols for the receiver.
Availability
- Available in OS X v10.5 and later.
See Also
Declared In
NSDateFormatter.hsetShortStandaloneMonthSymbols:
Sets the short standalone month symbols for the receiver.
Parameters
- array
An array of
NSStringobjects that specify the short standalone month symbols for the receiver.
Availability
- Available in OS X v10.5 and later.
See Also
Declared In
NSDateFormatter.hsetShortStandaloneQuarterSymbols:
Sets the short standalone quarter symbols for the receiver.
Parameters
- array
An array of
NSStringobjects that specify the short standalone quarter symbols for the receiver.
Availability
- Available in OS X v10.5 and later.
See Also
Declared In
NSDateFormatter.hsetShortStandaloneWeekdaySymbols:
Sets the short standalone weekday symbols for the receiver.
Parameters
- array
An array of
NSStringobjects that specify the short standalone weekday symbols for the receiver.
Availability
- Available in OS X v10.5 and later.
See Also
Declared In
NSDateFormatter.hsetShortWeekdaySymbols:
Sets the short weekday symbols for the receiver.
Parameters
- array
An array of
NSStringobjects that specify the short weekday symbols for the receiver.
Availability
- Available in OS X v10.4 and later.
See Also
Declared In
NSDateFormatter.hsetStandaloneMonthSymbols:
Sets the standalone month symbols for the receiver.
Parameters
- array
An array of
NSStringobjects that specify the standalone month symbols for the receiver.
Availability
- Available in OS X v10.5 and later.
See Also
Declared In
NSDateFormatter.hsetStandaloneQuarterSymbols:
Sets the standalone quarter symbols for the receiver.
Parameters
- array
An array of
NSStringobjects that specify the standalone quarter symbols for the receiver.
Availability
- Available in OS X v10.5 and later.
See Also
Declared In
NSDateFormatter.hsetStandaloneWeekdaySymbols:
Sets the standalone weekday symbols for the receiver.
Parameters
- array
An array of
NSStringobjects that specify the standalone weekday symbols for the receiver.
Availability
- Available in OS X v10.5 and later.
See Also
Declared In
NSDateFormatter.hsetTimeStyle:
Sets the time style of the receiver.
Parameters
- style
The time style for the receiver. For possible values, see NSDateFormatterStyle.
Availability
- Available in OS X v10.4 and later.
See Also
Declared In
NSDateFormatter.hsetTimeZone:
Sets the time zone for the receiver.
Parameters
- tz
The time zone for the receiver.
Availability
- Available in OS X v10.4 and later.
See Also
Declared In
NSDateFormatter.hsetTwoDigitStartDate:
Sets the two-digit start date for the receiver.
Parameters
- date
The earliest date that can be denoted by a two-digit year specifier.
Availability
- Available in OS X v10.4 and later.
See Also
Declared In
NSDateFormatter.hsetVeryShortMonthSymbols:
Sets the very short month symbols for the receiver.
Parameters
- array
An array of
NSStringobjects that specify the very short month symbols for the receiver.
Availability
- Available in OS X v10.5 and later.
See Also
Declared In
NSDateFormatter.hsetVeryShortStandaloneMonthSymbols:
Sets the very short standalone month symbols for the receiver.
Parameters
- array
An array of
NSStringobjects that specify the very short standalone month symbols for the receiver.
Availability
- Available in OS X v10.5 and later.
See Also
Declared In
NSDateFormatter.hsetVeryShortStandaloneWeekdaySymbols:
Sets the very short standalone weekday symbols for the receiver.
Parameters
- array
An array of
NSStringobjects that specify the very short standalone weekday symbols for the receiver.
Availability
- Available in OS X v10.5 and later.
See Also
Declared In
NSDateFormatter.hsetVeryShortWeekdaySymbols:
Sets the vert short weekday symbols for the receiver
Parameters
- array
An array of
NSStringobjects that specify the very short weekday symbols for the receiver.
Availability
- Available in OS X v10.5 and later.
See Also
Declared In
NSDateFormatter.hsetWeekdaySymbols:
Sets the weekday symbols for the receiver.
Parameters
- array
An array of
NSStringobjects that specify the weekday symbols for the receiver.
Availability
- Available in OS X v10.4 and later.
See Also
Declared In
NSDateFormatter.hshortMonthSymbols
Returns the array of short month symbols for the receiver.
Return Value
An array containing NSString objects representing the short month symbols for the receiver.
Availability
- Available in OS X v10.4 and later.
See Also
Declared In
NSDateFormatter.hshortQuarterSymbols
Returns the short quarter symbols for the receiver.
Return Value
An array containing NSString objects representing the short quarter symbols for the receiver.
Availability
- Available in OS X v10.5 and later.
See Also
Declared In
NSDateFormatter.hshortStandaloneMonthSymbols
Returns the short standalone month symbols for the receiver.
Return Value
An array of NSString objects that specify the short standalone month symbols for the receiver.
Availability
- Available in OS X v10.5 and later.
See Also
Declared In
NSDateFormatter.hshortStandaloneQuarterSymbols
Returns the short standalone quarter symbols for the receiver.
Return Value
An array containing NSString objects representing the short standalone quarter symbols for the receiver.
Availability
- Available in OS X v10.5 and later.
See Also
Declared In
NSDateFormatter.hshortStandaloneWeekdaySymbols
Returns the array of short standalone weekday symbols for the receiver.
Return Value
An array of NSString objects that specify the short standalone weekday symbols for the receiver.
Availability
- Available in OS X v10.5 and later.
See Also
Declared In
NSDateFormatter.hshortWeekdaySymbols
Returns the array of short weekday symbols for the receiver.
Return Value
An array of NSString objects that specify the short weekday symbols for the receiver.
Availability
- Available in OS X v10.4 and later.
See Also
Declared In
NSDateFormatter.hstandaloneMonthSymbols
Returns the standalone month symbols for the receiver.
Return Value
An array of NSString objects that specify the standalone month symbols for the receiver.
Availability
- Available in OS X v10.5 and later.
See Also
Declared In
NSDateFormatter.hstandaloneQuarterSymbols
Returns the standalone quarter symbols for the receiver.
Return Value
An array containing NSString objects representing the standalone quarter symbols for the receiver.
Availability
- Available in OS X v10.5 and later.
See Also
Declared In
NSDateFormatter.hstandaloneWeekdaySymbols
Returns the array of standalone weekday symbols for the receiver.
Return Value
An array of NSString objects that specify the standalone weekday symbols for the receiver.
Availability
- Available in OS X v10.5 and later.
See Also
Declared In
NSDateFormatter.hstringFromDate:
Returns a string representation of a given date formatted using the receiver’s current settings.
Parameters
- date
The date to format.
Return Value
A string representation of date formatted using the receiver’s current settings.
Availability
- Available in OS X v10.4 and later.
Declared In
NSDateFormatter.htimeStyle
Returns the time style of the receiver.
Return Value
The time style of the receiver. For possible values, see NSDateFormatterStyle.
Availability
- Available in OS X v10.4 and later.
See Also
Declared In
NSDateFormatter.htimeZone
Returns the time zone for the receiver.
Return Value
The time zone for the receiver.
Availability
- Available in OS X v10.4 and later.
See Also
Declared In
NSDateFormatter.htwoDigitStartDate
Returns the earliest date that can be denoted by a two-digit year specifier.
Return Value
The earliest date that can be denoted by a two-digit year specifier.
Discussion
If the two-digit start date is set to January 6, 1976, then “January 1, 76” is interpreted as New Year's Day in 2076, whereas “February 14, 76” is interpreted as Valentine's Day in 1976.
The default date is December 31, 1949.
Availability
- Available in OS X v10.4 and later.
See Also
Declared In
NSDateFormatter.hveryShortMonthSymbols
Returns the very short month symbols for the receiver.
Return Value
An array of NSString objects that specify the very short month symbols for the receiver.
Availability
- Available in OS X v10.5 and later.
See Also
Declared In
NSDateFormatter.hveryShortStandaloneMonthSymbols
Returns the very short month symbols for the receiver.
Return Value
An array of NSString objects that specify the very short standalone month symbols for the receiver.
Availability
- Available in OS X v10.5 and later.
See Also
Declared In
NSDateFormatter.hveryShortStandaloneWeekdaySymbols
Returns the array of very short standalone weekday symbols for the receiver.
Return Value
An array of NSString objects that specify the very short standalone weekday symbols for the receiver.
Availability
- Available in OS X v10.5 and later.
See Also
Declared In
NSDateFormatter.hveryShortWeekdaySymbols
Returns the array of very short weekday symbols for the receiver.
Return Value
An array of NSString objects that specify the very short weekday symbols for the receiver.
Availability
- Available in OS X v10.5 and later.
See Also
Declared In
NSDateFormatter.hweekdaySymbols
Returns the array of weekday symbols for the receiver.
Return Value
An array of NSString objects that specify the weekday symbols for the receiver.
Availability
- Available in OS X v10.4 and later.
See Also
Declared In
NSDateFormatter.hConstants
NSDateFormatterStyle
The following constants specify predefined format styles for dates and times.
typedef enum {
NSDateFormatterNoStyle = kCFDateFormatterNoStyle,
NSDateFormatterShortStyle = kCFDateFormatterShortStyle,
NSDateFormatterMediumStyle = kCFDateFormatterMediumStyle,
NSDateFormatterLongStyle = kCFDateFormatterLongStyle,
NSDateFormatterFullStyle = kCFDateFormatterFullStyle
} NSDateFormatterStyle;
Constants
NSDateFormatterNoStyleSpecifies no style.
Equal to
kCFDateFormatterNoStyle.Available in OS X v10.4 and later.
Declared in
NSDateFormatter.h.NSDateFormatterShortStyleSpecifies a short style, typically numeric only, such as “11/23/37” or “3:30pm”.
Equal to
kCFDateFormatterShortStyle.Available in OS X v10.4 and later.
Declared in
NSDateFormatter.h.NSDateFormatterMediumStyleSpecifies a medium style, typically with abbreviated text, such as “Nov 23, 1937”.
Equal to
kCFDateFormatterMediumStyle.Available in OS X v10.4 and later.
Declared in
NSDateFormatter.h.NSDateFormatterLongStyleSpecifies a long style, typically with full text, such as “November 23, 1937” or “3:30:32pm”.
Equal to
kCFDateFormatterLongStyle.Available in OS X v10.4 and later.
Declared in
NSDateFormatter.h.NSDateFormatterFullStyleSpecifies a full style with complete details, such as “Tuesday, April 12, 1952 AD” or “3:30:42pm PST”.
Equal to
kCFDateFormatterFullStyle.Available in OS X v10.4 and later.
Declared in
NSDateFormatter.h.
Discussion
The format for these date and time styles is not exact because they depend on the locale, user preference settings, and the operating system version. Do not use these constants if you want an exact format.
Availability
- Available in OS X v10.4 and later.
Declared In
NSDateFormatter.hNSDateFormatterBehavior
Constants that specify the behavior NSDateFormatter should exhibit.
typedef enum {
NSDateFormatterBehaviorDefault = 0,
NSDateFormatterBehavior10_0 = 1000,
NSDateFormatterBehavior10_4 = 1040,
} NSDateFormatterBehavior;
Constants
NSDateFormatterBehaviorDefaultSpecifies default formatting behavior.
Available in OS X v10.4 and later.
Declared in
NSDateFormatter.h.NSDateFormatterBehavior10_0Specifies formatting behavior equivalent to that in OS X v10.0.
Available in OS X v10.4 and later.
Declared in
NSDateFormatter.h.NSDateFormatterBehavior10_4Specifies formatting behavior equivalent for OS X v10.4.
Available in OS X v10.4 and later.
Declared in
NSDateFormatter.h.
Availability
- Available in OS X v10.4 and later.
Declared In
NSDateFormatter.h© 2012 Apple Inc. All Rights Reserved. (Last updated: 2012-09-19)