private static long parseDateTimeString(String str, int offset) {
        int year = 0, month = 0, day = 0, hour = 0, min = 0, sec = 0;
        boolean isUTC = false;
        boolean isValid = false;
        do {
            if (str == null) {
                break;
            }

            int length = str.length();
            if (length != 15 && length != 16) {
                // FORM#1 15 characters, such as "20060317T142115"
                // FORM#2 16 characters, such as "20060317T142115Z"
                break;
            }
            if (str.charAt(8) != 'T') {
                // charcter "T" must be used for separating date and time
                break;
            }
            if (length == 16) {
                if (str.charAt(15) != 'Z') {
                    // invalid format
                    break;
                }
                isUTC = true;
            }

            try {
                year = Integer.parseInt(str.substring(0, 4));
                month = Integer.parseInt(str.substring(4, 6)) - 1;  // 0-based
                day = Integer.parseInt(str.substring(6, 8));
                hour = Integer.parseInt(str.substring(9, 11));
                min = Integer.parseInt(str.substring(11, 13));
                sec = Integer.parseInt(str.substring(13, 15));
            } catch (NumberFormatException nfe) {
                break;
            }

            // check valid range
            int maxDayOfMonth = Grego.monthLength(year, month);
            if (year < 0 || month < 0 || month > 11 || day < 1 || day > maxDayOfMonth ||
                    hour < 0 || hour >= 24 || min < 0 || min >= 60 || sec < 0 || sec >= 60) {
                break;
            }

            isValid = true;
        } while(false);

        if (!isValid) {
            throw new IllegalArgumentException("Invalid date time string format");
        }
        // Calculate the time
        long time = Grego.fieldsToDay(year, month, day) * Grego.MILLIS_PER_DAY;
        time += (hour*Grego.MILLIS_PER_HOUR + min*Grego.MILLIS_PER_MINUTE + sec*Grego.MILLIS_PER_SECOND);
        if (!isUTC) {
            time -= offset;
        }
        return time;
    }
private static long parseDateTimeString ( String str , int offset ) { int year = 0 , month = 0 , day = 0 , hour = 0 , min = 0 , sec = 0 ; boolean isUTC = false ; boolean isValid = false ; do { if ( str == null ) { break ; } int length = str . length ( ) ; if ( length != 15 && length != 16 ) { break ; } if ( str . charAt ( 8 ) != 'T' ) { break ; } if ( length == 16 ) { if ( str . charAt ( 15 ) != 'Z' ) { break ; } isUTC = true ; } try { year = Integer . parseInt ( str . substring ( 0 , 4 ) ) ; month = Integer . parseInt ( str . substring ( 4 , 6 ) ) - 1 ; day = Integer . parseInt ( str . substring ( 6 , 8 ) ) ; hour = Integer . parseInt ( str . substring ( 9 , 11 ) ) ; min = Integer . parseInt ( str . substring ( 11 , 13 ) ) ; sec = Integer . parseInt ( str . substring ( 13 , 15 ) ) ; } catch ( NumberFormatException nfe ) { break ; } int maxDayOfMonth = Grego . monthLength ( year , month ) ; if ( year < 0 || month < 0 || month > 11 || day < 1 || day > maxDayOfMonth || hour < 0 || hour >= 24 || min < 0 || min >= 60 || sec < 0 || sec >= 60 ) { break ; } isValid = true ; } while ( false ) ; if ( ! isValid ) { throw new IllegalArgumentException ( "Invalid date time string format" ) ; } long time = Grego . fieldsToDay ( year , month , day ) * Grego . MILLIS_PER_DAY ; time += ( hour * Grego . MILLIS_PER_HOUR + min * Grego . MILLIS_PER_MINUTE + sec * Grego . MILLIS_PER_SECOND ) ; if ( ! isUTC ) { time -= offset ; } return time ; }
/*
Parse RFC2445 Date-Time form #1 DATE WITH LOCAL TIME and
#2 DATE WITH UTC TIME