Typedefs | |||
![]() | ![]() | typedef void* | UDateFormat |
![]() | ![]() | A date formatter. More... | |
![]() | ![]() | typedef enum UDateFormatStyle | UDateFormatStyle |
![]() | ![]() | typedef enum UDateFormatSymbolType | UDateFormatSymbolType |
![]() | ![]() | typedef struct UDateFormatSymbols | UDateFormatSymbols |
Enumerations | |||
![]() | ![]() | enum | UDateFormatStyle { UDAT_FULL, UDAT_LONG, UDAT_MEDIUM, UDAT_SHORT, UDAT_DEFAULT, UDAT_NONE } |
![]() | ![]() | The possible date/time format styles. More... | |
![]() | ![]() | enum | UDateFormatSymbolType { UDAT_ERAS, UDAT_MONTHS, UDAT_SHORT_MONTHS, UDAT_WEEKDAYS, UDAT_SHORT_WEEKDAYS, UDAT_AM_PMS, UDAT_LOCALIZED_CHARS } |
![]() | ![]() | The possible types of date format symbols. More... | |
Functions | |||
![]() | ![]() | U_CAPI UDateFormat* | udat_open (UDateFormatStyle timeStyle, UDateFormatStyle dateStyle, const char *locale, const UChar *tzID, int32_t tzIDLength, UErrorCode *status) |
![]() | ![]() | Open a new UDateFormat for formatting and parsing dates and times. More... | |
![]() | ![]() | U_CAPI UDateFormat* | udat_openPattern ( const UChar *pattern, int32_t patternLength, const char *locale, UErrorCode *status) |
![]() | ![]() | Open a new UDateFormat for formatting dates and times. More... | |
![]() | ![]() | U_CAPI void | udat_close (UDateFormat* format) |
![]() | ![]() | Close a UDateFormat. More... | |
![]() | ![]() | U_CAPI UDateFormat* | udat_clone (const UDateFormat *fmt, UErrorCode *status) |
![]() | ![]() | Open a copy of a UDateFormat. More... | |
![]() | ![]() | U_CAPI int32_t | udat_format ( const UDateFormat* format, UDate dateToFormat, UChar* result, int32_t resultLength, UFieldPosition* position, UErrorCode* status) |
![]() | ![]() | Format a date using an UDateFormat. More... | |
![]() | ![]() | U_CAPI UDate | udat_parse ( const UDateFormat* format, const UChar* text, int32_t textLength, int32_t *parsePos, UErrorCode *status) |
![]() | ![]() | Parse a string into an date/time using a UDateFormat. More... | |
![]() | ![]() | U_CAPI bool_t | udat_isLenient (const UDateFormat* fmt) |
![]() | ![]() | Determine if an UDateFormat will perform lenient parsing. More... | |
![]() | ![]() | U_CAPI void | udat_setLenient ( UDateFormat* fmt, bool_t isLenient) |
![]() | ![]() | Specify whether an UDateFormat will perform lenient parsing. More... | |
![]() | ![]() | U_CAPI const UCalendar* | udat_getCalendar (const UDateFormat* fmt) |
![]() | ![]() | Get the UCalendar associated with an UDateFormat. More... | |
![]() | ![]() | U_CAPI void | udat_setCalendar ( UDateFormat* fmt, const UCalendar* calendarToSet) |
![]() | ![]() | Set the UCalendar associated with an UDateFormat. More... | |
![]() | ![]() | U_CAPI const UNumberFormat* | udat_getNumberFormat (const UDateFormat* fmt) |
![]() | ![]() | Get the UNumberFormat associated with an UDateFormat. More... | |
![]() | ![]() | U_CAPI void | udat_setNumberFormat ( UDateFormat* fmt, const UNumberFormat* numberFormatToSet) |
![]() | ![]() | Set the UNumberFormat associated with an UDateFormat. More... | |
![]() | ![]() | U_CAPI const char* | udat_getAvailable (int32_t index) |
![]() | ![]() | Get a locale for which date/time formatting patterns are available. More... | |
![]() | ![]() | U_CAPI int32_t | udat_countAvailable (void) |
![]() | ![]() | Determine how many locales have date/time formatting patterns available. More... | |
![]() | ![]() | U_CAPI UDate | udat_get2DigitYearStart ( const UDateFormat *fmt, UErrorCode *status) |
![]() | ![]() | Get the year relative to which all 2-digit years are interpreted. More... | |
![]() | ![]() | U_CAPI void | udat_set2DigitYearStart ( UDateFormat *fmt, UDate d, UErrorCode *status) |
![]() | ![]() | Set the year relative to which all 2-digit years will be interpreted. More... | |
![]() | ![]() | U_CAPI int32_t | udat_toPattern ( const UDateFormat *fmt, bool_t localized, UChar *result, int32_t resultLength, UErrorCode *status) |
![]() | ![]() | Extract the pattern from a UDateFormat. More... | |
![]() | ![]() | U_CAPI void | udat_applyPattern ( UDateFormat *format, bool_t localized, const UChar *pattern, int32_t patternLength) |
![]() | ![]() | Set the pattern used by an UDateFormat. More... | |
![]() | ![]() | U_CAPI int32_t | udat_getSymbols (const UDateFormat *fmt, UDateFormatSymbolType type, int32_t index, UChar *result, int32_t resultLength, UErrorCode *status) |
![]() | ![]() | Get the symbols associated with an UDateFormat. More... | |
![]() | ![]() | U_CAPI int32_t | udat_countSymbols ( const UDateFormat *fmt, UDateFormatSymbolType type) |
![]() | ![]() | Count the number of particular symbols for an UDateFormat. More... | |
![]() | ![]() | U_CAPI void | udat_setSymbols ( UDateFormat *format, UDateFormatSymbolType type, int32_t index, UChar *value, int32_t valueLength, UErrorCode *status) |
![]() | ![]() | Set the symbols associated with an UDateFormat. More... | |
Variables | |||
![]() | ![]() | struct | UDateFormatSymbols |
![]() | ![]() | Date format symbols. More... |
Date Format C API consists of functions that convert dates and times from their internal representations to textual form and back again in a language-independent manner. Converting from the internal representation (milliseconds since midnight, January 1, 1970) to text is known as "formatting," and converting from text to millis is known as "parsing." We currently define only one concrete structure UDateFormat, which can handle pretty much all normal date formatting and parsing actions.
Date Format helps you to format and parse dates for any locale. Your code can be completely independent of the locale conventions for months, days of the week, or even the calendar format: lunar vs. solar.
To format a date for the current Locale with default time and date style, use one of the static factory methods:
. UErrorCode status; . UFieldPosition pos; . UChar *myString; . t_int32 myStrlen=0; . UDateFormat* dfmt = udat_open(UCAL_DEFAULT, UCAL_DEFAULT, NULL, "PST", &status); . myStrlen = udat_format(dfmt, myDate, NULL, myStrlen, &pos, &status); . if(status==U_BUFFER_OVERFLOW_ERROR){ . status=U_ZERO_ERROR; . myString=(UChar*)malloc(sizeof(UChar) * (myStrlen+1) ); . udat_format(dfmt, myDate, myString, myStrlen+1, &pos, &status); . }
. t_int32 i, myStrlen=0; . UChar* myString; . UDate myDateArr[] = { 0.0, 100000000.0, 2000000000.0 }; // test values . UDateFormat* df = udat_open(UCAL_DEFAULT, UCAL_DEFAULT, NULL, "GMT", &status); . for (i = 0; i < 3; ++i) { . myStrlen = udat_format(df, myDate, NULL, myStrlen, &pos, &status); . if(status==U_BUFFER_OVERFLOW_ERROR){ . status=U_ZERO_ERROR; . myString=(UChar*)malloc(sizeof(UChar) * (myStrlen+1) ); . udat_format(df, myDate, myString, myStrlen+1, &pos, &status); . } . printf("%s \n", austrdup(myString) ); //austrdup( a function used to convert UChar* to char*) . free(myString); . }
. UDateFormat* df = udat_open(UDAT_SHORT, UDAT_SHORT, "fr_FR", "GMT", &status);
. UErrorCode status = U_ZERO_ERROR; . t_int32 parsepos=0; . UDate myDate = udat_parse(df, myString, u_strlen(myString), &parsepos, &status);
You can also use forms of the parse and format methods with Parse Position and UFieldPosition to allow you to
typedef void* UDateFormat |
A date formatter.
For usage in C programs.
typedef enum UDateFormatStyle UDateFormatStyle |
typedef enum UDateFormatSymbolType UDateFormatSymbolType |
typedef struct UDateFormatSymbols UDateFormatSymbols |
enum UDateFormatStyle |
The possible date/time format styles.
UDAT_FULL | Full style. |
UDAT_LONG | Long style. |
UDAT_MEDIUM | Medium style. |
UDAT_SHORT | Short style. |
UDAT_DEFAULT | Default style. |
UDAT_NONE | No style. |
enum UDateFormatSymbolType |
The possible types of date format symbols.
UDAT_ERAS | The era names, for example AD. |
UDAT_MONTHS | The month names, for example February. |
UDAT_SHORT_MONTHS | The short month names, for example Feb. |
UDAT_WEEKDAYS | The weekday names, for example Monday. |
UDAT_SHORT_WEEKDAYS | The short weekday names, for example Mon. |
UDAT_AM_PMS | The AM/PM names, for example AM. |
UDAT_LOCALIZED_CHARS | The localized characters. |
U_CAPI UDateFormat * udat_open (UDateFormatStyle timeStyle, UDateFormatStyle dateStyle, const char * locale, const UChar * tzID, int32_t tzIDLength, UErrorCode * status) |
Open a new UDateFormat for formatting and parsing dates and times.
A UDateFormat may be used to format dates in calls to \Ref{udat_format}, and to parse dates in calls to \Ref{udat_parse}.
timeStyle | The style used to format times; one of UDAT_FULL_STYLE, UDAT_LONG_STYLE, UDAT_MEDIUM_STYLE, UDAT_SHORT_STYLE, or UDAT_DEFAULT_STYLE |
dateStyle | The style used to format dates; one of UDAT_FULL_STYLE, UDAT_LONG_STYLE, UDAT_MEDIUM_STYLE, UDAT_SHORT_STYLE, or UDAT_DEFAULT_STYLE |
locale | The locale specifying the formatting conventions |
tzID | A timezone ID specifying the timezone to use. If 0, use the default timezone. |
tzIDLength | The length of tzID, or -1 if null-terminated. |
status | A pointer to an UErrorCode to receive any errors |
U_CAPI UDateFormat * udat_openPattern (const UChar * pattern, int32_t patternLength, const char * locale, UErrorCode * status) |
Open a new UDateFormat for formatting dates and times.
A UDateFormat may be used to format dates in calls to \Ref{udat_format}, and to parse dates in calls to \Ref{udat_parse}.
pattern | A pattern specifying the format to use. |
patternLength | The number of characters in the pattern, or -1 if null-terminated. |
locale | The locale specifying the formatting conventions |
status | A pointer to an UErrorCode to receive any errors |
U_CAPI void udat_close (UDateFormat * format) |
Close a UDateFormat.
Once closed, a UDateFormat may no longer be used.
fmt | The formatter to close. |
U_CAPI UDateFormat * udat_clone (const UDateFormat * fmt, UErrorCode * status) |
Open a copy of a UDateFormat.
This function performs a deep copy.
fmt | The format to copy |
status | A pointer to an UErrorCode to receive any errors. |
U_CAPI int32_t udat_format (const UDateFormat * format, UDate dateToFormat, UChar * result, int32_t resultLength, UFieldPosition * position, UErrorCode * status) |
Format a date using an UDateFormat.
The date will be formatted using the conventions specified in \Ref{udat_open} or \Ref{udat_openPattern}
format | The formatter to use |
dateToFormat | The date to format |
result | A pointer to a buffer to receive the formatted number. |
resultLength | The maximum size of result. |
pos | If not 0, a UFieldPosition which will receive the information on a specific field. |
status | A pointer to an UErrorCode to receive any errors |
U_CAPI UDate udat_parse (const UDateFormat * format, const UChar * text, int32_t textLength, int32_t * parsePos, UErrorCode * status) |
Parse a string into an date/time using a UDateFormat.
The date will be parsed using the conventions specified in \Ref{udat_open} or \Ref{udat_openPattern}
fmt | The formatter to use. |
text | The text to parse. |
textLength | The length of text, or -1 if null-terminated. |
parsePos | If not 0, on input a pointer to an integer specifying the offset at which to begin parsing. If not 0, on output the offset at which parsing ended. |
status | A pointer to an UErrorCode to receive any errors |
U_CAPI bool_t udat_isLenient (const UDateFormat * fmt) |
Determine if an UDateFormat will perform lenient parsing.
With lenient parsing, the parser may use heuristics to interpret inputs that do not precisely match the pattern. With strict parsing, inputs must match the pattern.
fmt | The formatter to query |
U_CAPI void udat_setLenient (UDateFormat * fmt, bool_t isLenient) |
Specify whether an UDateFormat will perform lenient parsing.
With lenient parsing, the parser may use heuristics to interpret inputs that do not precisely match the pattern. With strict parsing, inputs must match the pattern.
fmt | The formatter to set |
isLenient | TRUE if fmt should perform lenient parsing, FALSE otherwise. |
U_CAPI const UCalendar * udat_getCalendar (const UDateFormat * fmt) |
Get the UCalendar associated with an UDateFormat.
A UDateFormat uses a UCalendar to convert a raw value to, for example, the day of the week.
fmt | The formatter to query. |
U_CAPI void udat_setCalendar (UDateFormat * fmt, const UCalendar * calendarToSet) |
Set the UCalendar associated with an UDateFormat.
A UDateFormat uses a UCalendar to convert a raw value to, for example, the day of the week.
fmt | The formatter to set. |
calendarToSet | A pointer to an UCalendar to be used by fmt. |
U_CAPI const UNumberFormat * udat_getNumberFormat (const UDateFormat * fmt) |
Get the UNumberFormat associated with an UDateFormat.
A UDateFormat uses a UNumberFormat to format numbers within a date, for example the day number.
fmt | The formatter to query. |
U_CAPI void udat_setNumberFormat (UDateFormat * fmt, const UNumberFormat * numberFormatToSet) |
Set the UNumberFormat associated with an UDateFormat.
A UDateFormat uses a UNumberFormat to format numbers within a date, for example the day number.
fmt | The formatter to set. |
numberFormatToSet | A pointer to the UNumberFormat to be used by fmt to format numbers. |
U_CAPI const char * udat_getAvailable (int32_t index) |
Get a locale for which date/time formatting patterns are available.
A UDateFormat in a locale returned by this function will perform the correct formatting and parsing for the locale.
index | The index of the desired locale. |
U_CAPI int32_t udat_countAvailable (void) |
Determine how many locales have date/time formatting patterns available.
This function is most useful as determining the loop ending condition for calls to \Ref{udat_getAvailable}.
U_CAPI UDate udat_get2DigitYearStart (const UDateFormat * fmt, UErrorCode * status) |
Get the year relative to which all 2-digit years are interpreted.
For example, if the 2-digit start year is 2100, the year 99 will be interpreted as 2199.
fmt | The formatter to query. |
status | A pointer to an UErrorCode to receive any errors |
U_CAPI void udat_set2DigitYearStart (UDateFormat * fmt, UDate d, UErrorCode * status) |
Set the year relative to which all 2-digit years will be interpreted.
For example, if the 2-digit start year is 2100, the year 99 will be interpreted as 2199.
fmt | The formatter to set. |
d | The year relative to which all 2-digit years will be interpreted. |
status | A pointer to an UErrorCode to receive any errors |
U_CAPI int32_t udat_toPattern (const UDateFormat * fmt, bool_t localized, UChar * result, int32_t resultLength, UErrorCode * status) |
Extract the pattern from a UDateFormat.
The pattern will follow the pattern syntax rules.
fmt | The formatter to query. |
localized | TRUE if the pattern should be localized, FALSE otherwise. |
result | A pointer to a buffer to receive the pattern. |
resultLength | The maximum size of result. |
status | A pointer to an UErrorCode to receive any errors |
U_CAPI void udat_applyPattern (UDateFormat * format, bool_t localized, const UChar * pattern, int32_t patternLength) |
Set the pattern used by an UDateFormat.
The pattern should follow the pattern syntax rules.
fmt | The formatter to set. |
localized | TRUE if the pattern is localized, FALSE otherwise. |
pattern | The new pattern |
patternLength | The length of pattern, or -1 if null-terminated. |
U_CAPI int32_t udat_getSymbols (const UDateFormat * fmt, UDateFormatSymbolType type, int32_t index, UChar * result, int32_t resultLength, UErrorCode * status) |
Get the symbols associated with an UDateFormat.
The symbols are what a UDateFormat uses to represent locale-specific data, for example month or day names.
fmt | The formatter to query. |
type | The type of symbols to get. One of UDAT_ERAS, UDAT_MONTHS, UDAT_SHORT_MONTHS, UDAT_WEEKDAYS, UDAT_SHORT_WEEKDAYS, UDAT_AM_PMS, or UDAT_LOCALIZED_CHARS |
index | The desired symbol of type type. |
result | A pointer to a buffer to receive the pattern. |
resultLength | The maximum size of result. |
status | A pointer to an UErrorCode to receive any errors |
U_CAPI int32_t udat_countSymbols (const UDateFormat * fmt, UDateFormatSymbolType type) |
Count the number of particular symbols for an UDateFormat.
This function is most useful as for detemining the loop termination condition for calls to \Ref{udat_getSymbols}.
fmt | The formatter to query. |
type | The type of symbols to count. One of UDAT_ERAS, UDAT_MONTHS, UDAT_SHORT_MONTHS, UDAT_WEEKDAYS, UDAT_SHORT_WEEKDAYS, UDAT_AM_PMS, or UDAT_LOCALIZED_CHARS |
U_CAPI void udat_setSymbols (UDateFormat * format, UDateFormatSymbolType type, int32_t index, UChar * value, int32_t valueLength, UErrorCode * status) |
Set the symbols associated with an UDateFormat.
The symbols are what a UDateFormat uses to represent locale-specific data, for example month or day names.
fmt | The formatter to set |
type | The type of symbols to set. One of UDAT_ERAS, UDAT_MONTHS, UDAT_SHORT_MONTHS, UDAT_WEEKDAYS, UDAT_SHORT_WEEKDAYS, UDAT_AM_PMS, or UDAT_LOCALIZED_CHARS |
index | The index of the symbol to set of type type. |
value | The new value |
valueLength | The length of value, or -1 if null-terminated |
status | A pointer to an UErrorCode to receive any errors |
struct UDateFormatSymbols |
Date format symbols.
For usage in C programs.