Contents

description(withCalendarFormat:timeZone:locale:)

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

Declaration

func description(withCalendarFormat format: String?, timeZone aTimeZone: TimeZone?, locale: Any?) -> String?

Parameters

  • format:

    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.

  • locale:

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

Related Documentation

Legacy Operations