Java Code Examples for java.text.SimpleDateFormat#set2DigitYearStart()

The following examples show how to use java.text.SimpleDateFormat#set2DigitYearStart() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: SimpleDateFormatTest.java    From j2objc with Apache License 2.0 6 votes vote down vote up
public void test2DigitYearStartIsCloned() throws Exception {
    // Test that get2DigitYearStart returns a clone.
    SimpleDateFormat sdf = new SimpleDateFormat();
    Date originalDate = sdf.get2DigitYearStart();
    assertNotSame(sdf.get2DigitYearStart(), originalDate);
    assertEquals(sdf.get2DigitYearStart(), originalDate);
    originalDate.setTime(0);
    assertFalse(sdf.get2DigitYearStart().equals(originalDate));
    // Test that set2DigitYearStart takes a clone.
    Date newDate = new Date();
    sdf.set2DigitYearStart(newDate);
    assertNotSame(sdf.get2DigitYearStart(), newDate);
    assertEquals(sdf.get2DigitYearStart(), newDate);
    newDate.setTime(0);
    assertFalse(sdf.get2DigitYearStart().equals(newDate));
}
 
Example 2
Source File: HttpCookie.java    From Java8CN with Apache License 2.0 5 votes vote down vote up
private long expiryDate2DeltaSeconds(String dateString) {
    Calendar cal = new GregorianCalendar(GMT);
    for (int i = 0; i < COOKIE_DATE_FORMATS.length; i++) {
        SimpleDateFormat df = new SimpleDateFormat(COOKIE_DATE_FORMATS[i],
                                                   Locale.US);
        cal.set(1970, 0, 1, 0, 0, 0);
        df.setTimeZone(GMT);
        df.setLenient(false);
        df.set2DigitYearStart(cal.getTime());
        try {
            cal.setTime(df.parse(dateString));
            if (!COOKIE_DATE_FORMATS[i].contains("yyyy")) {
                // 2-digit years following the standard set
                // out it rfc 6265
                int year = cal.get(Calendar.YEAR);
                year %= 100;
                if (year < 70) {
                    year += 2000;
                } else {
                    year += 1900;
                }
                cal.set(Calendar.YEAR, year);
            }
            return (cal.getTimeInMillis() - whenCreated) / 1000;
        } catch (Exception e) {
            // Ignore, try the next date format
        }
    }
    return 0;
}
 
Example 3
Source File: HttpCookie.java    From jdk8u-dev-jdk with GNU General Public License v2.0 5 votes vote down vote up
private long expiryDate2DeltaSeconds(String dateString) {
    Calendar cal = new GregorianCalendar(GMT);
    for (int i = 0; i < COOKIE_DATE_FORMATS.length; i++) {
        SimpleDateFormat df = new SimpleDateFormat(COOKIE_DATE_FORMATS[i],
                                                   Locale.US);
        cal.set(1970, 0, 1, 0, 0, 0);
        df.setTimeZone(GMT);
        df.setLenient(false);
        df.set2DigitYearStart(cal.getTime());
        try {
            cal.setTime(df.parse(dateString));
            if (!COOKIE_DATE_FORMATS[i].contains("yyyy")) {
                // 2-digit years following the standard set
                // out it rfc 6265
                int year = cal.get(Calendar.YEAR);
                year %= 100;
                if (year < 70) {
                    year += 2000;
                } else {
                    year += 1900;
                }
                cal.set(Calendar.YEAR, year);
            }
            return (cal.getTimeInMillis() - whenCreated) / 1000;
        } catch (Exception e) {
            // Ignore, try the next date format
        }
    }
    return 0;
}
 
Example 4
Source File: UmmalquraDateFormatTests.java    From ummalqura-calendar with MIT License 5 votes vote down vote up
private UmmalquraCalendar parseDate(String dateText, String fmt, Locale l)
        throws ParseException {
    UmmalquraCalendar uCal = new UmmalquraCalendar(l);

    SimpleDateFormat dateFormat = new SimpleDateFormat(fmt, l);
    dateFormat.setTimeZone(TimeZone.getTimeZone("UTC"));
    dateFormat.setCalendar(uCal);
    uCal.set(Calendar.YEAR, 1420);
    dateFormat.set2DigitYearStart(uCal.getTime());

    uCal.setTime(dateFormat.parse(dateText));
    return uCal;
}
 
Example 5
Source File: HttpCookie.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
private long expiryDate2DeltaSeconds(String dateString) {
    Calendar cal = new GregorianCalendar(GMT);
    for (int i = 0; i < COOKIE_DATE_FORMATS.length; i++) {
        SimpleDateFormat df = new SimpleDateFormat(COOKIE_DATE_FORMATS[i],
                                                   Locale.US);
        cal.set(1970, 0, 1, 0, 0, 0);
        df.setTimeZone(GMT);
        df.setLenient(false);
        df.set2DigitYearStart(cal.getTime());
        try {
            cal.setTime(df.parse(dateString));
            if (!COOKIE_DATE_FORMATS[i].contains("yyyy")) {
                // 2-digit years following the standard set
                // out it rfc 6265
                int year = cal.get(Calendar.YEAR);
                year %= 100;
                if (year < 70) {
                    year += 2000;
                } else {
                    year += 1900;
                }
                cal.set(Calendar.YEAR, year);
            }
            return (cal.getTimeInMillis() - whenCreated) / 1000;
        } catch (Exception e) {
            // Ignore, try the next date format
        }
    }
    return 0;
}
 
Example 6
Source File: DateUtils.java    From SaveVolley with Apache License 2.0 5 votes vote down vote up
/**
 * Parses the date value using the given date formats.
 *
 * @param dateValue the date value to parse
 * @param dateFormats the date formats to use
 * @param startDate During parsing, two digit years will be placed in the range
 * <code>startDate</code> to <code>startDate + 100 years</code>. This value may
 * be <code>null</code>. When <code>null</code> is given as a parameter, year
 * <code>2000</code> will be used.
 * @return the parsed date
 * @throws DateParseException if none of the dataFormats could parse the dateValue
 */
public static Date parseDate(String dateValue, String[] dateFormats, Date startDate)
        throws DateParseException {

    if (dateValue == null) {
        throw new IllegalArgumentException("dateValue is null");
    }
    if (dateFormats == null) {
        dateFormats = DEFAULT_PATTERNS;
    }
    if (startDate == null) {
        startDate = DEFAULT_TWO_DIGIT_YEAR_START;
    }
    // trim single quotes around date if present
    // see issue #5279
    if (dateValue.length() > 1 && dateValue.startsWith("'") && dateValue.endsWith("'")) {
        dateValue = dateValue.substring(1, dateValue.length() - 1);
    }

    for (String dateFormat : dateFormats) {
        SimpleDateFormat dateParser = DateFormatHolder.formatFor(dateFormat);
        dateParser.set2DigitYearStart(startDate);

        try {
            return dateParser.parse(dateValue);
        } catch (ParseException pe) {
            // ignore this exception, we will try the next format
        }
    }

    // we were unable to parse the date
    throw new DateParseException("Unable to parse the date " + dateValue);
}
 
Example 7
Source File: HttpCookie.java    From jdk8u_jdk with GNU General Public License v2.0 5 votes vote down vote up
private long expiryDate2DeltaSeconds(String dateString) {
    Calendar cal = new GregorianCalendar(GMT);
    for (int i = 0; i < COOKIE_DATE_FORMATS.length; i++) {
        SimpleDateFormat df = new SimpleDateFormat(COOKIE_DATE_FORMATS[i],
                                                   Locale.US);
        cal.set(1970, 0, 1, 0, 0, 0);
        df.setTimeZone(GMT);
        df.setLenient(false);
        df.set2DigitYearStart(cal.getTime());
        try {
            cal.setTime(df.parse(dateString));
            if (!COOKIE_DATE_FORMATS[i].contains("yyyy")) {
                // 2-digit years following the standard set
                // out it rfc 6265
                int year = cal.get(Calendar.YEAR);
                year %= 100;
                if (year < 70) {
                    year += 2000;
                } else {
                    year += 1900;
                }
                cal.set(Calendar.YEAR, year);
            }
            return (cal.getTimeInMillis() - whenCreated) / 1000;
        } catch (Exception e) {
            // Ignore, try the next date format
        }
    }
    return 0;
}
 
Example 8
Source File: DateUtils.java    From jus with Apache License 2.0 5 votes vote down vote up
/**
 * Parses the date value using the given date formats.
 *
 * @param dateValue the date value to parse
 * @param dateFormats the date formats to use
 * @param startDate During parsing, two digit years will be placed in the range
 * <code>startDate</code> to <code>startDate + 100 years</code>. This value may
 * be <code>null</code>. When <code>null</code> is given as a parameter, year
 * <code>2000</code> will be used.
 *
 * @return the parsed date
 *
 * @throws DateParseException if none of the dataFormats could parse the dateValue
 */
public static Date parseDate(
        String dateValue,
        String[] dateFormats,
        Date startDate
) throws DateParseException {

    if (dateValue == null) {
        throw new IllegalArgumentException("dateValue is null");
    }
    if (dateFormats == null) {
        dateFormats = DEFAULT_PATTERNS;
    }
    if (startDate == null) {
        startDate = DEFAULT_TWO_DIGIT_YEAR_START;
    }
    // trim single quotes around date if present
    // see issue #5279
    if (dateValue.length() > 1
            && dateValue.startsWith("'")
            && dateValue.endsWith("'")
            ) {
        dateValue = dateValue.substring (1, dateValue.length() - 1);
    }

    for (String dateFormat : dateFormats) {
        SimpleDateFormat dateParser = DateFormatHolder.formatFor(dateFormat);
        dateParser.set2DigitYearStart(startDate);

        try {
            return dateParser.parse(dateValue);
        } catch (ParseException pe) {
            // ignore this exception, we will try the next format
        }
    }

    // we were unable to parse the date
    throw new DateParseException("Unable to parse the date " + dateValue);
}
 
Example 9
Source File: HttpCookie.java    From openjdk-8-source with GNU General Public License v2.0 5 votes vote down vote up
private long expiryDate2DeltaSeconds(String dateString) {
    Calendar cal = new GregorianCalendar(GMT);
    for (int i = 0; i < COOKIE_DATE_FORMATS.length; i++) {
        SimpleDateFormat df = new SimpleDateFormat(COOKIE_DATE_FORMATS[i],
                                                   Locale.US);
        cal.set(1970, 0, 1, 0, 0, 0);
        df.setTimeZone(GMT);
        df.setLenient(false);
        df.set2DigitYearStart(cal.getTime());
        try {
            cal.setTime(df.parse(dateString));
            if (!COOKIE_DATE_FORMATS[i].contains("yyyy")) {
                // 2-digit years following the standard set
                // out it rfc 6265
                int year = cal.get(Calendar.YEAR);
                year %= 100;
                if (year < 70) {
                    year += 2000;
                } else {
                    year += 1900;
                }
                cal.set(Calendar.YEAR, year);
            }
            return (cal.getTimeInMillis() - whenCreated) / 1000;
        } catch (Exception e) {
            // Ignore, try the next date format
        }
    }
    return 0;
}
 
Example 10
Source File: HttpCookie.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
private long expiryDate2DeltaSeconds(String dateString) {
    Calendar cal = new GregorianCalendar(GMT);
    for (int i = 0; i < COOKIE_DATE_FORMATS.length; i++) {
        SimpleDateFormat df = new SimpleDateFormat(COOKIE_DATE_FORMATS[i],
                                                   Locale.US);
        cal.set(1970, 0, 1, 0, 0, 0);
        df.setTimeZone(GMT);
        df.setLenient(false);
        df.set2DigitYearStart(cal.getTime());
        try {
            cal.setTime(df.parse(dateString));
            if (!COOKIE_DATE_FORMATS[i].contains("yyyy")) {
                // 2-digit years following the standard set
                // out it rfc 6265
                int year = cal.get(Calendar.YEAR);
                year %= 100;
                if (year < 70) {
                    year += 2000;
                } else {
                    year += 1900;
                }
                cal.set(Calendar.YEAR, year);
            }
            return (cal.getTimeInMillis() - whenCreated) / 1000;
        } catch (Exception e) {
            // Ignore, try the next date format
        }
    }
    return 0;
}
 
Example 11
Source File: HttpCookie.java    From jdk1.8-source-analysis with Apache License 2.0 5 votes vote down vote up
private long expiryDate2DeltaSeconds(String dateString) {
    Calendar cal = new GregorianCalendar(GMT);
    for (int i = 0; i < COOKIE_DATE_FORMATS.length; i++) {
        SimpleDateFormat df = new SimpleDateFormat(COOKIE_DATE_FORMATS[i],
                                                   Locale.US);
        cal.set(1970, 0, 1, 0, 0, 0);
        df.setTimeZone(GMT);
        df.setLenient(false);
        df.set2DigitYearStart(cal.getTime());
        try {
            cal.setTime(df.parse(dateString));
            if (!COOKIE_DATE_FORMATS[i].contains("yyyy")) {
                // 2-digit years following the standard set
                // out it rfc 6265
                int year = cal.get(Calendar.YEAR);
                year %= 100;
                if (year < 70) {
                    year += 2000;
                } else {
                    year += 1900;
                }
                cal.set(Calendar.YEAR, year);
            }
            return (cal.getTimeInMillis() - whenCreated) / 1000;
        } catch (Exception e) {
            // Ignore, try the next date format
        }
    }
    return 0;
}
 
Example 12
Source File: HttpCookie.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
private long expiryDate2DeltaSeconds(String dateString) {
    Calendar cal = new GregorianCalendar(GMT);
    for (int i = 0; i < COOKIE_DATE_FORMATS.length; i++) {
        SimpleDateFormat df = new SimpleDateFormat(COOKIE_DATE_FORMATS[i],
                                                   Locale.US);
        cal.set(1970, 0, 1, 0, 0, 0);
        df.setTimeZone(GMT);
        df.setLenient(false);
        df.set2DigitYearStart(cal.getTime());
        try {
            cal.setTime(df.parse(dateString));
            if (!COOKIE_DATE_FORMATS[i].contains("yyyy")) {
                // 2-digit years following the standard set
                // out it rfc 6265
                int year = cal.get(Calendar.YEAR);
                year %= 100;
                if (year < 70) {
                    year += 2000;
                } else {
                    year += 1900;
                }
                cal.set(Calendar.YEAR, year);
            }
            return (cal.getTimeInMillis() - whenCreated) / 1000;
        } catch (Exception e) {
            // Ignore, try the next date format
        }
    }
    return 0;
}
 
Example 13
Source File: FastDateParserTest.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
@Test
// Check that all Locales can parse the formats we use
public void testParses() throws Exception {
    for(final Locale locale : Locale.getAvailableLocales()) {
        for(final TimeZone tz : new TimeZone[]{NEW_YORK, GMT}) {
            final Calendar cal = Calendar.getInstance(tz);
            for(final int year : new int[]{2003, 1940, 1868, 1867, 0, -1940}) {
                // http://docs.oracle.com/javase/6/docs/technotes/guides/intl/calendar.doc.html
                if (year < 1868 && locale.equals(FastDateParser.JAPANESE_IMPERIAL)) {
                    continue; // Japanese imperial calendar does not support eras before 1868
                }
                cal.clear();
                if (year < 0) {
                    cal.set(-year, 1, 10);
                    cal.set(Calendar.ERA, GregorianCalendar.BC);
                } else {
                    cal.set(year, 1, 10);
                }
                final Date in = cal.getTime();
                for(final String format : new String[]{LONG_FORMAT, SHORT_FORMAT}) {
                    final SimpleDateFormat sdf = new SimpleDateFormat(format, locale);
                    if (format.equals(SHORT_FORMAT)) {
                        if (year < 1930) {
                            sdf.set2DigitYearStart(cal.getTime());
                        }
                    }
                    final String fmt = sdf.format(in);
                    try {
                        final Date out = sdf.parse(fmt);

                        assertEquals(locale.toString()+" "+year+" "+ format+ " "+tz.getID(), in, out);
                    } catch (final ParseException pe) {
                        System.out.println(fmt+" "+locale.toString()+" "+year+" "+ format+ " "+tz.getID());
                        throw pe;
                    }
                }
            }
        }
    }
}
 
Example 14
Source File: HttpCookie.java    From Bytecoder with Apache License 2.0 5 votes vote down vote up
private long expiryDate2DeltaSeconds(String dateString) {
    Calendar cal = new GregorianCalendar(GMT);
    for (int i = 0; i < COOKIE_DATE_FORMATS.length; i++) {
        SimpleDateFormat df = new SimpleDateFormat(COOKIE_DATE_FORMATS[i],
                                                   Locale.US);
        cal.set(1970, 0, 1, 0, 0, 0);
        df.setTimeZone(GMT);
        df.setLenient(false);
        df.set2DigitYearStart(cal.getTime());
        try {
            cal.setTime(df.parse(dateString));
            if (!COOKIE_DATE_FORMATS[i].contains("yyyy")) {
                // 2-digit years following the standard set
                // out it rfc 6265
                int year = cal.get(Calendar.YEAR);
                year %= 100;
                if (year < 70) {
                    year += 2000;
                } else {
                    year += 1900;
                }
                cal.set(Calendar.YEAR, year);
            }
            return (cal.getTimeInMillis() - whenCreated) / 1000;
        } catch (Exception e) {
            // Ignore, try the next date format
        }
    }
    return 0;
}
 
Example 15
Source File: HttpCookie.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
private long expiryDate2DeltaSeconds(String dateString) {
    Calendar cal = new GregorianCalendar(GMT);
    for (int i = 0; i < COOKIE_DATE_FORMATS.length; i++) {
        SimpleDateFormat df = new SimpleDateFormat(COOKIE_DATE_FORMATS[i],
                                                   Locale.US);
        cal.set(1970, 0, 1, 0, 0, 0);
        df.setTimeZone(GMT);
        df.setLenient(false);
        df.set2DigitYearStart(cal.getTime());
        try {
            cal.setTime(df.parse(dateString));
            if (!COOKIE_DATE_FORMATS[i].contains("yyyy")) {
                // 2-digit years following the standard set
                // out it rfc 6265
                int year = cal.get(Calendar.YEAR);
                year %= 100;
                if (year < 70) {
                    year += 2000;
                } else {
                    year += 1900;
                }
                cal.set(Calendar.YEAR, year);
            }
            return (cal.getTimeInMillis() - whenCreated) / 1000;
        } catch (Exception e) {
            // Ignore, try the next date format
        }
    }
    return 0;
}
 
Example 16
Source File: HttpCookie.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
private long expiryDate2DeltaSeconds(String dateString) {
    Calendar cal = new GregorianCalendar(GMT);
    for (int i = 0; i < COOKIE_DATE_FORMATS.length; i++) {
        SimpleDateFormat df = new SimpleDateFormat(COOKIE_DATE_FORMATS[i],
                                                   Locale.US);
        cal.set(1970, 0, 1, 0, 0, 0);
        df.setTimeZone(GMT);
        df.setLenient(false);
        df.set2DigitYearStart(cal.getTime());
        try {
            cal.setTime(df.parse(dateString));
            if (!COOKIE_DATE_FORMATS[i].contains("yyyy")) {
                // 2-digit years following the standard set
                // out it rfc 6265
                int year = cal.get(Calendar.YEAR);
                year %= 100;
                if (year < 70) {
                    year += 2000;
                } else {
                    year += 1900;
                }
                cal.set(Calendar.YEAR, year);
            }
            return (cal.getTimeInMillis() - whenCreated) / 1000;
        } catch (Exception e) {
            // Ignore, try the next date format
        }
    }
    return 0;
}
 
Example 17
Source File: FastDateParserTest.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
@Test
// Check that all Locales can parse the formats we use
public void testParses() throws Exception {
    for(Locale locale : Locale.getAvailableLocales()) {
        for(TimeZone tz : new TimeZone[]{NEW_YORK, GMT}) {
            Calendar cal = Calendar.getInstance(tz);
            for(int year : new int[]{2003, 1940, 1868, 1867, 0, -1940}) {
                // http://docs.oracle.com/javase/6/docs/technotes/guides/intl/calendar.doc.html
                if (year < 1868 && locale.equals(FastDateParser.JAPANESE_IMPERIAL)) {
                    continue; // Japanese imperial calendar does not support eras before 1868
                }
                cal.clear();
                if (year < 0) {
                    cal.set(-year, 1, 10);
                    cal.set(Calendar.ERA, GregorianCalendar.BC);
                } else {
                    cal.set(year, 1, 10);
                }
                Date in = cal.getTime();
                for(String format : new String[]{LONG_FORMAT, SHORT_FORMAT}) {
                    SimpleDateFormat sdf = new SimpleDateFormat(format, locale);
                    if (format.equals(SHORT_FORMAT)) {
                        if (year < 1930) {
                            sdf.set2DigitYearStart(cal.getTime());
                        }
                    }
                    String fmt = sdf.format(in);
                    try {
                        Date out = sdf.parse(fmt);

                        assertEquals(locale.toString()+" "+year+" "+ format+ " "+tz.getID(), in, out);
                    } catch (ParseException pe) {
                        System.out.println(fmt+" "+locale.toString()+" "+year+" "+ format+ " "+tz.getID());
                        throw pe;
                    }
                }
            }
        }
    }
}
 
Example 18
Source File: HttpCookie.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
private long expiryDate2DeltaSeconds(String dateString) {
    Calendar cal = new GregorianCalendar(GMT);
    for (int i = 0; i < COOKIE_DATE_FORMATS.length; i++) {
        SimpleDateFormat df = new SimpleDateFormat(COOKIE_DATE_FORMATS[i],
                                                   Locale.US);
        cal.set(1970, 0, 1, 0, 0, 0);
        df.setTimeZone(GMT);
        df.setLenient(false);
        df.set2DigitYearStart(cal.getTime());
        try {
            cal.setTime(df.parse(dateString));
            if (!COOKIE_DATE_FORMATS[i].contains("yyyy")) {
                // 2-digit years following the standard set
                // out it rfc 6265
                int year = cal.get(Calendar.YEAR);
                year %= 100;
                if (year < 70) {
                    year += 2000;
                } else {
                    year += 1900;
                }
                cal.set(Calendar.YEAR, year);
            }
            return (cal.getTimeInMillis() - whenCreated) / 1000;
        } catch (Exception e) {
            // Ignore, try the next date format
        }
    }
    return 0;
}
 
Example 19
Source File: HttpCookie.java    From dragonwell8_jdk with GNU General Public License v2.0 5 votes vote down vote up
private long expiryDate2DeltaSeconds(String dateString) {
    Calendar cal = new GregorianCalendar(GMT);
    for (int i = 0; i < COOKIE_DATE_FORMATS.length; i++) {
        SimpleDateFormat df = new SimpleDateFormat(COOKIE_DATE_FORMATS[i],
                                                   Locale.US);
        cal.set(1970, 0, 1, 0, 0, 0);
        df.setTimeZone(GMT);
        df.setLenient(false);
        df.set2DigitYearStart(cal.getTime());
        try {
            cal.setTime(df.parse(dateString));
            if (!COOKIE_DATE_FORMATS[i].contains("yyyy")) {
                // 2-digit years following the standard set
                // out it rfc 6265
                int year = cal.get(Calendar.YEAR);
                year %= 100;
                if (year < 70) {
                    year += 2000;
                } else {
                    year += 1900;
                }
                cal.set(Calendar.YEAR, year);
            }
            return (cal.getTimeInMillis() - whenCreated) / 1000;
        } catch (Exception e) {
            // Ignore, try the next date format
        }
    }
    return 0;
}
 
Example 20
Source File: HttpCookie.java    From jdk8u60 with GNU General Public License v2.0 4 votes vote down vote up
private long expiryDate2DeltaSeconds(String dateString) {
    Calendar cal = new GregorianCalendar(GMT);
    for (int i = 0; i < COOKIE_DATE_FORMATS.length; i++) {
        SimpleDateFormat df = new SimpleDateFormat(COOKIE_DATE_FORMATS[i],
                                                   Locale.US);
        cal.set(1970, 0, 1, 0, 0, 0);
        df.setTimeZone(GMT);
        df.setLenient(false);
        df.set2DigitYearStart(cal.getTime());
        try {
            cal.setTime(df.parse(dateString));
            if (!COOKIE_DATE_FORMATS[i].contains("yyyy")) {
                // 2-digit years following the standard set
                // out it rfc 6265
                int year = cal.get(Calendar.YEAR);
                year %= 100;
                if (year < 70) {
                    year += 2000;
                } else {
                    year += 1900;
                }
                cal.set(Calendar.YEAR, year);
            }
            return (cal.getTimeInMillis() - whenCreated) / 1000;
        } catch (Exception e) {
            // Ignore, try the next date format
        }
    }
    return 0;
}