Type Method

stringFromDate:timeZone:formatOptions:

Creates a representation of the specified date with a given time zone and format options.

Declaration

+ (NSString *)stringFromDate:(NSDate *)date timeZone:(NSTimeZone *)timeZone formatOptions:(NSISO8601DateFormatOptions)formatOptions;

Parameters

date

The date to be represented.

timeZone

The time zone used.

formatOptions

The options used. For possible values, see NSISO8601DateFormatOptions.

Return Value

A user-readable string representing the date.

Discussion

This method uses a date formatter configured with the specified time zone and format options. The following code examples produce the same string value:

NSDate *date = [NSDate date];
NSString *string;
 
NSISO8601DateFormatter *formatter = [[NSISO8601DateFormatter alloc] init];
string = [formatter stringFromDate:date];
 
NSTimeZone *GMT = [NSTimeZone timeZoneWithAbbreviation: @"GMT"];
NSISO8601DateFormatOptions options = NSISO8601DateFormatWithInternetDateTime | NSISO8601DateFormatWithDashSeparatorInDate | NSISO8601DateFormatWithColonSeparatorInTime | NSISO8601DateFormatWithTimeZone;
string = [NSISO8601DateFormatter stringFromDate:date timeZone:GMT formatOptions:options];

See Also

Converting ISO 8601 Dates

- stringFromDate:

Creates and returns an ISO 8601 formatted string representation of the specified date.

- dateFromString:

Creates and returns a date object from the specified ISO 8601 formatted string representation.