Code example for ParsePosition

Methods: getIndex, setErrorIndex, setIndex

0
     * @return      A Date, or null if the input could not be parsed 
     * @stable ICU 2.0 
     */ 
    public Date parse(String text, ParsePosition pos) {
        Date result = null;
        int start = pos.getIndex();
        TimeZone tzsav = calendar.getTimeZone();
        calendar.clear();
        parse(text, calendar, pos);
        if (pos.getIndex() != start) {
            try { 
                result = calendar.getTime();
            } catch (IllegalArgumentException e) {
                // This occurs if the calendar is non-lenient and there is 
                // an out-of-range field.  We don't know which field was 
                // illegal so we set the error index to the start. 
                pos.setIndex(start);
                pos.setErrorIndex(start);
            } 
        } 
        // Restore TimeZone 
        calendar.setTimeZone(tzsav);
        return result;