Instance Method

descriptionWithCalendarFormat:timeZone:locale:

Returns a string representation of the date formatted as specified by given conversion specifiers.

Declaration

- (NSString *)descriptionWithCalendarFormat:(NSString *)format timeZone:(NSTimeZone *)aTimeZone locale:(id)locale;

Parameters

formatString

The format for the returned string (see Date and Number Formatters in OS X v10.0 to 10.3 for a discussion of how to create the format string). Pass nil to use the default format string, “%Y-%m-%d %H:%M:%S %z” (this conforms to the international format YYYY-MM-DD HH:MM:SS ±HHMM.)

aTimeZone

The time zone in which to represent the receiver. Pass nil to use the default time zone—specific to the current locale.

localeDictionary

An NSDictionary object containing locale data. To use the user's preferences, you can use [[NSUserDefaults standardUserDefaults] dictionaryRepresentation].

If you pass nil or an instance of NSLocale, NSDate uses the system default locale—this is not the same as the current user's locale.

Return Value

A string representation of the receiver, formatted as specified by the given conversion specifiers.

Discussion

There are several problems with the implementation of this method that cannot be fixed for compatibility reasons. To format a date, you should use a date formatter object instead (see NSDateFormatter and Data Formatting Guide).

You could use this method to print the current time as follows:

sprintf(aString, "The current time is %s\n", [[[NSDate  date]
    descriptionWithCalendarFormat:@"%H:%M:%S %Z" timeZone:nil
    locale:[[NSUserDefaults standardUserDefaults] dictionaryRepresentation]]
        UTF8String]);

See Also

Legacy Operations

+ dateWithNaturalLanguageString:

Creates and returns a date object set to the date and time specified by a given string.

Deprecated
+ dateWithNaturalLanguageString:locale:

Creates and returns a date object set to the date and time specified by a given string.

Deprecated
+ dateWithString:

Creates and returns a date object with a date and time value specified by a given string in the international string representation format (YYYY-MM-DD HH:MM:SS ±HHMM).

Deprecated
- initWithString:

Returns a date object initialized with a date and time value specified by a given string in the international string representation format.

Deprecated
- addTimeInterval:

Returns a new date object that is set to a given number of seconds relative to the receiver.

Deprecated
- dateWithCalendarFormat:timeZone:

Converts the receiver to a calendar date with a given format string and time zone.

Deprecated