| Derived from | |
| Framework | CoreFoundation/CoreFoundation.h |
| Companion guide | |
| Declared in | CFDateFormatter.h CFLocale.h |
CFDateFormatter objects format the textual representations of CFDate and CFAbsoluteTime objects, and convert textual representations of dates and times into CFDate and CFAbsoluteTime objects. You can express the representation of dates and times very flexibly, for example “Thu 22 Dec 1994” is just as acceptable as “12/22/94.” You specify how strings are formatted and parsed by setting a format string and other properties of a CFDateFormatter object. The format of the format string itself is defined by Unicode Technical Standard #35.
The CFDateFormatter opaque type is available in Mac OS X v10.3 and later.
CFDateFormatterCopyProperty
CFDateFormatterGetDateStyle
CFDateFormatterGetFormat
CFDateFormatterGetLocale
CFDateFormatterGetTimeStyle
Returns a copy of a date formatter’s value for a given key.
CFTypeRef CFDateFormatterCopyProperty ( CFDateFormatterRef formatter, CFStringRef key );
The date formatter to examine.
The property key for the value to obtain. See “Date Formatter Property Keys” for a description of possible values for this parameter.
A CFType object that is a copy of the property value for key, or NULL if there is no value specified for key. Ownership follows the Create Rule.
CFDateFormatter.hCreates a new CFDateFormatter object, localized to the given locale, which will format dates to the given date and time styles.
CFDateFormatterRef CFDateFormatterCreate ( CFAllocatorRef allocator, CFLocaleRef locale, CFDateFormatterStyle dateStyle, CFDateFormatterStyle timeStyle );
The allocator to use to allocate memory for the new object. Pass NULL or kCFAllocatorDefault to use the current default allocator.
The locale to use for localization. If NULL uses the default system local. Use CFLocaleCopyCurrent to specify the locale of the current user.
The date style to use when formatting dates. See “Date Formatter Styles” for possible values.
The time style to use when formatting times. See “Date Formatter Styles” for possible values.
A new date formatter, localized to the given locale, which will format dates to the given date and time styles. Returns NULL if there was a problem creating the object. Ownership follows the Create Rule.
You can use kCFDateFormatterNoStyle to suppress output for the date or time. The following code fragment illustrates the creation and use of a date formatter that only outputs the date information (memory management is omitted for clarity).
CFLocaleRef locale = CFLocaleCreate(kCFAllocatorDefault, CFSTR("en_GB")); |
CFDateFormatterRef formatter = CFDateFormatterCreate( |
kCFAllocatorDefault, locale, kCFDateFormatterMediumStyle, kCFDateFormatterNoStyle); |
CFDateRef date = CFDateCreate(kCFAllocatorDefault, 123456); |
CFStringRef dateAsString = CFDateFormatterCreateStringWithDate ( |
kCFAllocatorDefault, formatter, date); |
CFShow(dateAsString); |
// outputs "2 Jan 2001" |
CFDateFormatter.hReturns a date object representing a given string.
CFDateRef CFDateFormatterCreateDateFromString ( CFAllocatorRef allocator, CFDateFormatterRef formatter, CFStringRef string, CFRange *rangep );
The allocator to use to allocate memory for the new object. Pass NULL or kCFAllocatorDefault to use the current default allocator.
The date formatter object to use to parse string.
The string that contains the date.
A reference to the range within the string specifying the substring to be parsed. If NULL, the whole string is parsed. Upon return, contains the range that defines the extent of the parse (may be less than the given range).
A new date that represents string, or NULL if there was a problem creating the object. Ownership follows the Create Rule.
CFDateFormatter.hReturns a string representation of the given absolute time using the specified date formatter.
CFStringRef CFDateFormatterCreateStringWithAbsoluteTime ( CFAllocatorRef allocator, CFDateFormatterRef formatter, CFAbsoluteTime at );
The allocator to use to allocate memory for the new object. Pass NULL or kCFAllocatorDefault to use the current default allocator.
The date formatter object that specifies the format of the returned string.
The absolute time for which to generate a string representation.
A new string that represents at in the specified format. Returns NULL if there was a problem creating the object. Ownership follows the Create Rule.
CFDateFormatter.hReturns a string representation of the given date using the specified date formatter.
CFStringRef CFDateFormatterCreateStringWithDate ( CFAllocatorRef allocator, CFDateFormatterRef formatter, CFDateRef date );
The allocator to use to allocate memory for the new object. Pass NULL or kCFAllocatorDefault to use the current default allocator.
The date formatter object that specifies the format of the returned string.
The date object for which to create a string representation.
A new string that represents date in the specified format. Returns NULL if there was a problem creating the object. Ownership follows the Create Rule.
CFDateFormatter.hReturns an absolute time object representing a given string.
Boolean CFDateFormatterGetAbsoluteTimeFromString ( CFDateFormatterRef formatter, CFStringRef string, CFRange *rangep, CFAbsoluteTime *atp );
The date formatter object to use to parse string.
The string that contains the time to be parsed.
Reference to the range within the string specifying the substring to be parsed. If NULL, the whole string is parsed. On return, the range that defines the extent of the parse (may be less than the given range).
An absolute time value, returned by reference, that represents string. Ownership follows the Get Rule.
true if the string was parsed successfully, otherwise false.
CFDateFormatter.hReturns the date style used to create the given date formatter object.
CFDateFormatterStyle CFDateFormatterGetDateStyle ( CFDateFormatterRef formatter );
The date formatter to examine.
The date style used to create formatter.
CFDateFormatter.hReturns a format string for the given date formatter object.
CFStringRef CFDateFormatterGetFormat ( CFDateFormatterRef formatter );
The date formatter to examine.
The format string for formatter as was specified by calling the CFDateFormatterSetFormat function, or derived from the date formatter’s date or time styles. Ownership follows the Get Rule.
CFDateFormatter.hReturns the locale object used to create the given date formatter object.
CFLocaleRef CFDateFormatterGetLocale ( CFDateFormatterRef formatter );
The date formatter object to examine.
The locale object used to create formatter. Ownership follows the Get Rule.
CFDateFormatter.hReturns the time style used to create the given date formatter object.
CFDateFormatterStyle CFDateFormatterGetTimeStyle ( CFDateFormatterRef formatter );
The date formatter to examine.
The time style used to create formatter.
CFDateFormatter.h
Returns the type identifier for CFDateFormatter.
CFTypeID CFDateFormatterGetTypeID ( void );
The type identifier for the CFDateFormatter opaque type.
CFDateFormatter.h
Sets the format string of the given date formatter to the specified value.
void CFDateFormatterSetFormat ( CFDateFormatterRef formatter, CFStringRef formatString );
The date formatter to modify.
The format string for formatter. The syntax of this string is defined by Unicode Technical Standard #35..
The format string may override other properties previously set using other functions. If this function is not called, the default value of the format string is derived from the date formatter’s date and time styles.
CFDateFormatter.h
Sets a date formatter property using a key-value pair.
void CFDateFormatterSetProperty ( CFDateFormatterRef formatter, CFStringRef key, CFTypeRef value );
The date formatter to modify.
The name of the property to set. See “Date Formatter Property Keys” for a description of possible values for this parameter.
The value for key. This should be a CFType object corresponding to the specified key.
CFDateFormatter.hA reference to a CFDateFormatter object.
typedef struct __CFDateFormatter *CFDateFormatterRef;
CFDateFormatter.hData type for predefined date and time format styles.
typedef CFIndex CFDateFormatterStyle;
For possible values, see “Date Formatter Styles.”
CFDateFormatter.hPredefined date and time format styles.
enum {
kCFDateFormatterNoStyle = 0,
kCFDateFormatterShortStyle = 1,
kCFDateFormatterMediumStyle = 2,
kCFDateFormatterLongStyle = 3,
kCFDateFormatterFullStyle = 4
};
kCFDateFormatterNoStyleSpecifies no output.
You use this constant to suppress output for the date or time (see CFDateFormatterCreate for more details).
Available in Mac OS X v10.3 and later.
Declared in CFDateFormatter.h
kCFDateFormatterShortStyleSpecifies a short style, typically numeric only, such as “11/23/37” or “3:30pm”.
Available in Mac OS X v10.3 and later.
Declared in CFDateFormatter.h
kCFDateFormatterMediumStyleSpecifies a medium style, typically with abbreviated text, such as “Nov 23, 1937”.
Available in Mac OS X v10.3 and later.
Declared in CFDateFormatter.h
kCFDateFormatterLongStyleSpecifies a long style, typically with full text, such as “November 23, 1937” or “3:30:32pm”.
Available in Mac OS X v10.3 and later.
Declared in CFDateFormatter.h
kCFDateFormatterFullStyleSpecifies a full style with complete details, such as “Tuesday, April 12, 1952 AD” or “3:30:42pm PST”.
Available in Mac OS X v10.3 and later.
Declared in CFDateFormatter.h
The format for these date and time styles is not exact because they depend on the locale, user preference settings, and the operating system version. Do not use these constants if you want an exact format, for example if you are parsing an external data file which contains date information in a fixed format. There are several different “lengths” of the formats:
"long" era names, for example "Anno Domini" instead of "AD"
"very short" names for months and weekdays; for example, "F" instead of "Friday"
"standalone" names for months and weekdays (for some locales or languages, a month name displayed in isolation needs to be written differently than a month name within a displayed date)
names of quarters; for example, "Q2" for a short quarter name
CFDateFormatter.h
Keys used in key-value pairs to discover and specify the value of date formatter properties—used in conjunction with CFDateFormatterCopyProperty and CFDateFormatterSetProperty.
const CFStringRef kCFDateFormatterIsLenient; const CFStringRef kCFDateFormatterTimeZone; const CFStringRef kCFDateFormatterCalendarName; const CFStringRef kCFDateFormatterDefaultFormat; const CFStringRef kCFDateFormatterTwoDigitStartDate; const CFStringRef kCFDateFormatterDefaultDate; const CFStringRef kCFDateFormatterCalendar; const CFStringRef kCFDateFormatterEraSymbols; const CFStringRef kCFDateFormatterMonthSymbols; const CFStringRef kCFDateFormatterShortMonthSymbols; const CFStringRef kCFDateFormatterWeekdaySymbols; const CFStringRef kCFDateFormatterShortWeekdaySymbols; const CFStringRef kCFDateFormatterAMSymbol; const CFStringRef kCFDateFormatterPMSymbol; const CFStringRef kCFDateFormatterLongEraSymbols; const CFStringRef kCFDateFormatterVeryShortMonthSymbols; const CFStringRef kCFDateFormatterStandaloneMonthSymbols; const CFStringRef kCFDateFormatterShortStandaloneMonthSymbols; const CFStringRef kCFDateFormatterVeryShortStandaloneMonthSymbols; const CFStringRef kCFDateFormatterVeryShortWeekdaySymbols; const CFStringRef kCFDateFormatterStandaloneWeekdaySymbols; const CFStringRef kCFDateFormatterShortStandaloneWeekdaySymbols; const CFStringRef kCFDateFormatterVeryShortStandaloneWeekdaySymbols; const CFStringRef kCFDateFormatterQuarterSymbols; const CFStringRef kCFDateFormatterShortQuarterSymbols; const CFStringRef kCFDateFormatterStandaloneQuarterSymbols; const CFStringRef kCFDateFormatterShortStandaloneQuarterSymbols; const CFStringRef kCFDateFormatterGregorianStartDate;
kCFDateFormatterIsLenientSpecifies the lenient property, a CFBoolean object where a true value indicates that the parsing of strings into date or absolute time values will be fuzzy.
The formatter will use heuristics to guess at the date which is intended by the string. As with any guessing, it may get the result date wrong (that is, a date other than that which was intended).
Available in Mac OS X v10.3 and later.
Declared in CFDateFormatter.h
kCFDateFormatterTimeZoneSpecifies the time zone property, a CFTimeZone object.
Available in Mac OS X v10.3 and later.
Declared in CFDateFormatter.h
kCFDateFormatterCalendarNameSpecifies the calendar name, a CFString object.
With Mac OS X version 10.3, kCFGregorianCalendar is the only possible value. With Mac OS X version 10.4, kCFGregorianCalendar and other calendar names are specified by CFLocale.
Available in Mac OS X v10.3 and later.
Declared in CFDateFormatter.h
kCFDateFormatterDefaultFormatThe original format string for the formatter (given the date & time style and locale specified at creation).
Available in Mac OS X v10.3 and later.
Declared in CFDateFormatter.h
kCFDateFormatterTwoDigitStartDateSpecifies the property representing the date from which two-digit years start, a CFDate object.
Available in Mac OS X v10.4 and later.
Declared in CFDateFormatter.h
kCFDateFormatterDefaultDateSpecifies the default date property, a CFDate object.
Available in Mac OS X v10.4 and later.
Declared in CFDateFormatter.h
kCFDateFormatterCalendarSpecifies the calendar property, a CFCalendar object.
Available in Mac OS X v10.4 and later.
Declared in CFDateFormatter.h
kCFDateFormatterEraSymbolsSpecifies the era symbols property, a CFArray of CFString objects.
Available in Mac OS X v10.4 and later.
Declared in CFDateFormatter.h
kCFDateFormatterMonthSymbolsSpecifies the month symbols property, a CFArray of CFString objects.
Available in Mac OS X v10.4 and later.
Declared in CFDateFormatter.h
kCFDateFormatterShortMonthSymbolsSpecifies the short month symbols property, a CFArray of CFString objects.
Available in Mac OS X v10.4 and later.
Declared in CFDateFormatter.h
kCFDateFormatterWeekdaySymbolsSpecifies the weekday symbols property, a CFArray of CFString objects.
Available in Mac OS X v10.4 and later.
Declared in CFDateFormatter.h
kCFDateFormatterShortWeekdaySymbolsSpecifies the short weekday symbols property, a CFArray of CFString objects.
Available in Mac OS X v10.4 and later.
Declared in CFDateFormatter.h
kCFDateFormatterAMSymbolSpecifies the AM symbol property, a CFString object.
Available in Mac OS X v10.4 and later.
Declared in CFDateFormatter.h
kCFDateFormatterPMSymbolSpecifies the PM symbol property, a CFString object.
Available in Mac OS X v10.4 and later.
Declared in CFDateFormatter.h
kCFDateFormatterLongEraSymbolsSpecifies the long era symbols property, a CFArray of CFString objects.
Available in Mac OS X v10.5 and later.
Declared in CFDateFormatter.h
kCFDateFormatterVeryShortMonthSymbolsSpecifies the very short month symbols property, a CFArray of CFString objects.
Available in Mac OS X v10.5 and later.
Declared in CFDateFormatter.h
kCFDateFormatterStandaloneMonthSymbolsSpecifies the standalone month symbols property, a CFArray of CFString objects.
Available in Mac OS X v10.5 and later.
Declared in CFDateFormatter.h
kCFDateFormatterShortStandaloneMonthSymbolsSpecifies the short standalone month symbols property, a CFArray of CFString objects.
Available in Mac OS X v10.5 and later.
Declared in CFDateFormatter.h
kCFDateFormatterVeryShortStandaloneMonthSymbolsSpecifies the very short standalone month symbols property, a CFArray of CFString objects.
Available in Mac OS X v10.5 and later.
Declared in CFDateFormatter.h
kCFDateFormatterVeryShortWeekdaySymbolsSpecifies the very short weekday symbols property, a CFArray of CFString objects.
Available in Mac OS X v10.5 and later.
Declared in CFDateFormatter.h
kCFDateFormatterStandaloneWeekdaySymbolsSpecifies the standalone weekday symbols property, a CFArray of CFString objects.
Available in Mac OS X v10.5 and later.
Declared in CFDateFormatter.h
kCFDateFormatterShortStandaloneWeekdaySymbolsSpecifies the short standalone weekday symbols property, a CFArray of CFString objects.
Available in Mac OS X v10.5 and later.
Declared in CFDateFormatter.h
kCFDateFormatterVeryShortStandaloneWeekdaySymbolsSpecifies the very short standalone weekday symbols property, a CFArray of CFString objects.
Available in Mac OS X v10.5 and later.
Declared in CFDateFormatter.h
kCFDateFormatterQuarterSymbolsSpecifies the quarter symbols property, a CFArray of CFString objects.
Available in Mac OS X v10.5 and later.
Declared in CFDateFormatter.h
kCFDateFormatterShortQuarterSymbolsSpecifies the short quarter symbols property, a CFArray of CFString objects.
Available in Mac OS X v10.5 and later.
Declared in CFDateFormatter.h
kCFDateFormatterStandaloneQuarterSymbolsSpecifies the standalone quarter symbols property, a CFArray of CFString objects.
Available in Mac OS X v10.5 and later.
Declared in CFDateFormatter.h
kCFDateFormatterShortStandaloneQuarterSymbolsSpecifies the short standalone quarter symbols property, a CFArray of CFString objects.
Available in Mac OS X v10.5 and later.
Declared in CFDateFormatter.h
kCFDateFormatterGregorianStartDateSpecifies the Gregorian start date property, a CFDate object.
This is used to specify the start date for the Gregorian calendar switch from the Julian calendar. Different locales switched at different times. Normally you should just accept the locale's default date for the switch.
Available in Mac OS X v10.5 and later.
Declared in CFDateFormatter.h
The values for these keys are all CFType objects. The specific types for each key are specified above.
CFDateFormatter.h
Calendar names used by CFDateFormatter.
const CFStringRef kCFGregorianCalendar;
kCFGregorianCalendarThe name of the calendar currently supported by the kCFDateFormatterCalendarName property.
Available in Mac OS X v10.3 and later.
Declared in CFLocale.h
CFDateFormatter.h
Last updated: 2007-05-23