Class: NSDateFormatter
- Inherits:
-
NSFormatter
- Object
- NSObject
- NSFormatter
- NSDateFormatter
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.
Class Method Summary (collapse)
-
+ dateFormatFromTemplate:options:locale:
Returns a localized date format string representing the given date format components arranged appropriately for the specified locale.
-
+ defaultFormatterBehavior
Returns the default formatting behavior for instances of the class.
-
+ localizedStringFromDate:dateStyle:timeStyle:
Returns string representation of a given date formatted for the current locale using the specified date and time styles.
-
+ setDefaultFormatterBehavior:
Sets the default formatting behavior for instances of the class.
Instance Method Summary (collapse)
-
- AMSymbol
Returns the AM symbol for the receiver.
-
- calendar
Returns the calendar for the receiver.
-
- dateFormat
Returns the date format string used by the receiver.
-
- dateFromString:
Returns a date representation of a given string interpreted using the receiver’s current settings.
-
- dateStyle
Returns the date style of the receiver.
-
- defaultDate
Returns the default date for the receiver.
-
- doesRelativeDateFormatting
Returns a Boolean value that indicates whether the receiver uses phrases such as “today” and “tomorrow” for the date component.
-
- eraSymbols
Returns the era symbols for the receiver.
-
- formatterBehavior
Returns the formatter behavior for the receiver.
-
- generatesCalendarDates
You should not use this method.
-
- getObjectValue: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.
-
- gregorianStartDate
Returns the start date of the Gregorian calendar for the receiver.
-
- isLenient
Returns a Boolean value that indicates whether the receiver uses heuristics when parsing a string.
-
- locale
Returns the locale for the receiver.
-
- longEraSymbols
Returns the long era symbols for the receiver.
-
- monthSymbols
Returns the month symbols for the receiver.
-
- PMSymbol
Returns the PM symbol for the receiver.
-
- quarterSymbols
Returns the quarter symbols for the receiver.
-
- setAMSymbol:
Sets the AM symbol for the receiver.
-
- setCalendar:
Sets the calendar for the receiver.
-
- setDateFormat:
Sets the date format for the receiver.
-
- setDateStyle:
Sets the date style of the receiver.
-
- setDefaultDate:
Sets the default date for the receiver.
-
- setDoesRelativeDateFormatting:
Specifies whether the receiver uses phrases such as “today” and “tomorrow” for the date component.
-
- setEraSymbols:
Sets the era symbols for the receiver.
-
- setFormatterBehavior:
Sets the formatter behavior for the receiver.
-
- setGeneratesCalendarDates:
You should not use this method.
-
- setGregorianStartDate:
Sets the start date of the Gregorian calendar for the receiver.
-
- setLenient:
Sets whether the receiver uses heuristics when parsing a string.
-
- setLocale:
Sets the locale for the receiver.
-
- setLongEraSymbols:
Sets the long era symbols for the receiver.
-
- setMonthSymbols:
Sets the month symbols for the receiver.
-
- setPMSymbol:
Sets the PM symbol for the receiver.
-
- setQuarterSymbols:
Sets the quarter symbols for the receiver.
-
- setShortMonthSymbols:
Sets the short month symbols for the receiver.
-
- setShortQuarterSymbols:
Sets the short quarter symbols for the receiver.
-
- setShortStandaloneMonthSymbols:
Sets the short standalone month symbols for the receiver.
-
- setShortStandaloneQuarterSymbols:
Sets the short standalone quarter symbols for the receiver.
-
- setShortStandaloneWeekdaySymbols:
Sets the short standalone weekday symbols for the receiver.
-
- setShortWeekdaySymbols:
Sets the short weekday symbols for the receiver.
-
- setStandaloneMonthSymbols:
Sets the standalone month symbols for the receiver.
-
- setStandaloneQuarterSymbols:
Sets the standalone quarter symbols for the receiver.
-
- setStandaloneWeekdaySymbols:
Sets the standalone weekday symbols for the receiver.
-
- setTimeStyle:
Sets the time style of the receiver.
-
- setTimeZone:
Sets the time zone for the receiver.
-
- setTwoDigitStartDate:
Sets the two-digit start date for the receiver.
-
- setVeryShortMonthSymbols:
Sets the very short month symbols for the receiver.
-
- setVeryShortStandaloneMonthSymbols:
Sets the very short standalone month symbols for the receiver.
-
- setVeryShortStandaloneWeekdaySymbols:
Sets the very short standalone weekday symbols for the receiver.
-
- setVeryShortWeekdaySymbols:
Sets the vert short weekday symbols for the receiver.
-
- setWeekdaySymbols:
Sets the weekday symbols for the receiver.
-
- shortMonthSymbols
Returns the array of short month symbols for the receiver.
-
- shortQuarterSymbols
Returns the short quarter symbols for the receiver.
-
- shortStandaloneMonthSymbols
Returns the short standalone month symbols for the receiver.
-
- shortStandaloneQuarterSymbols
Returns the short standalone quarter symbols for the receiver.
-
- shortStandaloneWeekdaySymbols
Returns the array of short standalone weekday symbols for the receiver.
-
- shortWeekdaySymbols
Returns the array of short weekday symbols for the receiver.
-
- standaloneMonthSymbols
Returns the standalone month symbols for the receiver.
-
- standaloneQuarterSymbols
Returns the standalone quarter symbols for the receiver.
-
- standaloneWeekdaySymbols
Returns the array of standalone weekday symbols for the receiver.
-
- stringFromDate:
Returns a string representation of a given date formatted using the receiver’s current settings.
-
- timeStyle
Returns the time style of the receiver.
-
- timeZone
Returns the time zone for the receiver.
-
- twoDigitStartDate
Returns the earliest date that can be denoted by a two-digit year specifier.
-
- veryShortMonthSymbols
Returns the very short month symbols for the receiver.
-
- veryShortStandaloneMonthSymbols
Returns the very short month symbols for the receiver.
-
- veryShortStandaloneWeekdaySymbols
Returns the array of very short standalone weekday symbols for the receiver.
-
- veryShortWeekdaySymbols
Returns the array of very short weekday symbols for the receiver.
-
- weekdaySymbols
Returns the array of weekday symbols for the receiver.
Methods inherited from NSFormatter
#attributedStringForObjectValue:withDefaultAttributes:, #editingStringForObjectValue:, #getObjectValue:forString:errorDescription:, #isPartialStringValid:newEditingString:errorDescription:, #isPartialStringValid:proposedSelectedRange:originalString:originalSelectedRange:errorDescription:, #stringForObjectValue:
Methods inherited from NSObject
#!, #!=, #!~, #, #==, #===, #=~, #Rational, #__callee__, #__method__, #__send__, #__type__, `, alloc, allocWithZone:, #autoContentAccessingProxy, autoload, autoload?, autorelease_pool, #awakeAfterUsingCoder:, binding, block_given?, caller, cancelPreviousPerformRequestsWithTarget:, cancelPreviousPerformRequestsWithTarget:selector:object:, catch, class, classFallbacksForKeyedArchiver, #classForCoder, #classForKeyedArchiver, classForKeyedUnarchiver, #clone, conformsToProtocol:, #copy, copyWithZone:, #dealloc, #define_singleton_method, description, display, #doesNotRecognizeSelector:, #dup, #enum_for, #eql?, #equal?, #extend, fail, #finalize, format, #forwardInvocation:, #forwardingTargetForSelector:, framework, #freeze, #frozen?, getpass, gets, global_variables, #init, initialize, #initialize_clone, #initialize_copy, #initialize_dup, #inspect, instanceMethodForSelector:, instanceMethodSignatureForSelector:, #instance_eval, #instance_exec, #instance_of?, #instance_variable_defined?, #instance_variable_get, #instance_variable_set, #instance_variables, instancesRespondToSelector:, isSubclassOfClass:, #is_a?, iterator?, #kind_of?, lambda, load, load_bridge_support_file, load_plist, local_variables, loop, #method, #methodForSelector:, #methodSignatureForSelector:, #methods, #mutableCopy, mutableCopyWithZone:, new, #nil?, open, p, #performSelector:onThread:withObject:waitUntilDone:, #performSelector:onThread:withObject:waitUntilDone:modes:, #performSelector:withObject:afterDelay:, #performSelector:withObject:afterDelay:inModes:, #performSelectorInBackground:withObject:, #performSelectorOnMainThread:withObject:waitUntilDone:, #performSelectorOnMainThread:withObject:waitUntilDone:modes:, print, printf, #private_methods, proc, #protected_methods, #public_method, #public_methods, #public_send, putc, puts, raise, rand, readline, readlines, #replacementObjectForCoder:, #replacementObjectForKeyedArchiver:, require, resolveClassMethod:, resolveInstanceMethod:, #respond_to?, #respond_to_missing?, select, #send, setVersion:, #singleton_methods, sprintf, srand, superclass, #taint, #tainted?, #tap, test, throw, #to_plist, #to_s, trace_var, trap, #trust, #untaint, untrace_var, #untrust, #untrusted?, version
Constructor Details
This class inherits a constructor from NSObject
Dynamic Method Handling
This class handles dynamic methods through the method_missing method in the class NSObject
Class Method Details
+ (String) dateFormatFromTemplate(template, options:opts, locale:locale)
Returns a localized date format string representing the given date format components arranged appropriately for the specified locale. 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:
+ (NSDateFormatterBehavior) defaultFormatterBehavior
Returns the default formatting behavior for instances of the class. For iOS and for OS X applications linked against OS X v10.5 and later, the default is NSDateFormatterBehavior10_4.
+ (String) localizedStringFromDate(date, dateStyle:dateStyle, timeStyle:timeStyle)
Returns string representation of a given date formatted for the current locale using the specified date and time styles. 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:
+ (Object) setDefaultFormatterBehavior(behavior)
Sets the default formatting behavior for instances of the class.
Instance Method Details
- (String) AMSymbol
Returns the AM symbol for the receiver.
- (NSCalendar) calendar
Returns the calendar for the receiver.
- (String) dateFormat
Returns the date format string used by the receiver. See Data Formatting Guide for a list of the conversion specifiers permitted in date format strings.
- (NSDate) dateFromString(string)
Returns a date representation of a given string interpreted using the receiver’s current settings.
- (NSDateFormatterStyle) dateStyle
Returns the date style of the receiver.
- (NSDate) defaultDate
Returns the default date for the receiver. The default default date is nil.
- (Boolean) doesRelativeDateFormatting
Returns a Boolean value that indicates whether the receiver uses phrases such as “today” and “tomorrow” for the date component. For a full discussion, see setDoesRelativeDateFormatting:.
- (Array) eraSymbols
Returns the era symbols for the receiver.
- (NSDateFormatterBehavior) formatterBehavior
Returns the formatter behavior for the receiver.
- (Boolean) generatesCalendarDates
You should not use this method. NSCalendarDate is no longer supported; you should not use this method.
- (Boolean) getObjectValue(obj, forString:string, range:rangep, error: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.
- (NSDate) gregorianStartDate
Returns the start date of the Gregorian calendar for the receiver.
- (Boolean) isLenient
Returns a Boolean value that indicates whether the receiver uses heuristics when parsing a string.
- (NSLocale) locale
Returns the locale for the receiver.
- (Array) longEraSymbols
Returns the long era symbols for the receiver
- (Array) monthSymbols
Returns the month symbols for the receiver.
- (String) PMSymbol
Returns the PM symbol for the receiver.
- (Array) quarterSymbols
Returns the quarter symbols for the receiver.
- (Object) setAMSymbol(string)
Sets the AM symbol for the receiver.
- (Object) setCalendar(calendar)
Sets the calendar for the receiver.
- (Object) setDateFormat(string)
Sets the date format for the receiver.
- (Object) setDateStyle(style)
Sets the date style of the receiver.
- (Object) setDefaultDate(date)
Sets the default date for the receiver.
- (Object) setDoesRelativeDateFormatting(b)
Specifies whether the receiver uses phrases such as “today” and “tomorrow” for the date component. 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.
- (Object) setEraSymbols(array)
Sets the era symbols for the receiver.
- (Object) setFormatterBehavior(behavior)
Sets the formatter behavior for the receiver.
- (Object) setGeneratesCalendarDates(b)
You should not use this method. NSCalendarDate is no longer supported; you should not use this method.
- (Object) setGregorianStartDate(date)
Sets the start date of the Gregorian calendar for the receiver.
- (Object) setLenient(b)
Sets whether the receiver uses heuristics when parsing a string. 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).
- (Object) setLocale(locale)
Sets the locale for the receiver.
- (Object) setLongEraSymbols(array)
Sets the long era symbols for the receiver.
- (Object) setMonthSymbols(array)
Sets the month symbols for the receiver.
- (Object) setPMSymbol(string)
Sets the PM symbol for the receiver.
- (Object) setQuarterSymbols(array)
Sets the quarter symbols for the receiver.
- (Object) setShortMonthSymbols(array)
Sets the short month symbols for the receiver.
- (Object) setShortQuarterSymbols(array)
Sets the short quarter symbols for the receiver.
- (Object) setShortStandaloneMonthSymbols(array)
Sets the short standalone month symbols for the receiver.
- (Object) setShortStandaloneQuarterSymbols(array)
Sets the short standalone quarter symbols for the receiver.
- (Object) setShortStandaloneWeekdaySymbols(array)
Sets the short standalone weekday symbols for the receiver.
- (Object) setShortWeekdaySymbols(array)
Sets the short weekday symbols for the receiver.
- (Object) setStandaloneMonthSymbols(array)
Sets the standalone month symbols for the receiver.
- (Object) setStandaloneQuarterSymbols(array)
Sets the standalone quarter symbols for the receiver.
- (Object) setStandaloneWeekdaySymbols(array)
Sets the standalone weekday symbols for the receiver.
- (Object) setTimeStyle(style)
Sets the time style of the receiver.
- (Object) setTimeZone(tz)
Sets the time zone for the receiver.
- (Object) setTwoDigitStartDate(date)
Sets the two-digit start date for the receiver.
- (Object) setVeryShortMonthSymbols(array)
Sets the very short month symbols for the receiver.
- (Object) setVeryShortStandaloneMonthSymbols(array)
Sets the very short standalone month symbols for the receiver.
- (Object) setVeryShortStandaloneWeekdaySymbols(array)
Sets the very short standalone weekday symbols for the receiver.
- (Object) setVeryShortWeekdaySymbols(array)
Sets the vert short weekday symbols for the receiver
- (Object) setWeekdaySymbols(array)
Sets the weekday symbols for the receiver.
- (Array) shortMonthSymbols
Returns the array of short month symbols for the receiver.
- (Array) shortQuarterSymbols
Returns the short quarter symbols for the receiver.
- (Array) shortStandaloneMonthSymbols
Returns the short standalone month symbols for the receiver.
- (Array) shortStandaloneQuarterSymbols
Returns the short standalone quarter symbols for the receiver.
- (Array) shortStandaloneWeekdaySymbols
Returns the array of short standalone weekday symbols for the receiver.
- (Array) shortWeekdaySymbols
Returns the array of short weekday symbols for the receiver.
- (Array) standaloneMonthSymbols
Returns the standalone month symbols for the receiver.
- (Array) standaloneQuarterSymbols
Returns the standalone quarter symbols for the receiver.
- (Array) standaloneWeekdaySymbols
Returns the array of standalone weekday symbols for the receiver.
- (String) stringFromDate(date)
Returns a string representation of a given date formatted using the receiver’s current settings.
- (NSDateFormatterStyle) timeStyle
Returns the time style of the receiver.
- (NSTimeZone) timeZone
Returns the time zone for the receiver.
- (NSDate) twoDigitStartDate
Returns the earliest date that can be denoted by a two-digit year specifier. 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.
- (Array) veryShortMonthSymbols
Returns the very short month symbols for the receiver.
- (Array) veryShortStandaloneMonthSymbols
Returns the very short month symbols for the receiver.
- (Array) veryShortStandaloneWeekdaySymbols
Returns the array of very short standalone weekday symbols for the receiver.
- (Array) veryShortWeekdaySymbols
Returns the array of very short weekday symbols for the receiver.
- (Array) weekdaySymbols
Returns the array of weekday symbols for the receiver.