Logo Search packages:      
Sourcecode: icu version File versions  Download package

U_STABLE UDate U_EXPORT2 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 udat_open

format 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
The value of the parsed date/time
See also:
udat_format ICU 2.0

Definition at line 195 of file udat.cpp.

References ParsePosition::getErrorIndex(), ParsePosition::getIndex(), NULL, ParsePosition::setIndex(), U_FAILURE, and U_PARSE_ERROR.

    if(U_FAILURE(*status)) return (UDate)0;

    const UnicodeString src((UBool)(textLength == -1), text, textLength);
    ParsePosition pp;
    int32_t stackParsePos = 0;
    UDate res;

    if(parsePos == NULL) {
        parsePos = &stackParsePos;


    res = ((DateFormat*)format)->parse(src, pp);

    if(pp.getErrorIndex() == -1)
        *parsePos = pp.getIndex();
    else {
        *parsePos = pp.getErrorIndex();
        *status = U_PARSE_ERROR;

    return res;

Generated by  Doxygen 1.6.0   Back to index