Type Method

localizedStringFromDate:dateStyle:timeStyle:

Returns a string representation of a given date, formatted for the current locale using the specified date and time styles.

Declaration

+ (NSString *)localizedStringFromDate:(NSDate *)date dateStyle:(NSDateFormatterStyle)dstyle timeStyle:(NSDateFormatterStyle)tstyle;

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.formatterBehavior = NSDateFormatterBehavior10_4;
formatter.dateStyle = dateStyle;
formatter.timeStyle = timeStyle;
NSString *result = [formatter stringForObjectValue:date];

See Also

Converting Objects

- dateFromString:

Returns a date representation of a given string interpreted using the receiver’s current settings.

- stringFromDate:

Returns a string representation of a given date formatted using the receiver’s current settings.

- 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.

Beta Software

This documentation contains preliminary information about an API or technology in development. This information is subject to change, and software implemented according to this documentation should be tested with final operating system software.

Learn more about using Apple's beta software