Example usage for org.apache.pdfbox.util DateConverter toCalendar

List of usage examples for org.apache.pdfbox.util DateConverter toCalendar

Introduction

In this page you can find the example usage for org.apache.pdfbox.util DateConverter toCalendar.

Prototype

public static Calendar toCalendar(String text) 

Source Link

Document

Returns the Calendar for a given string containing a date, or null if it cannot be parsed.

Usage

From source file:org.alfresco.repo.content.metadata.PdfBoxMetadataExtracterTest.java

License:Open Source License

/**
 * Test that will show when the workaround is in place.
 *//*from  w w w. j  a v a  2  s. c  o m*/
public void testDateConversion() throws Exception {
    Calendar c = DateConverter.toCalendar("D:20050526205258+01'00'");
    assertEquals(2005, c.get(Calendar.YEAR));
    assertEquals(05 - 1, c.get(Calendar.MONTH));
    assertEquals(26, c.get(Calendar.DAY_OF_MONTH));
    assertEquals(20, c.get(Calendar.HOUR_OF_DAY));
    assertEquals(52, c.get(Calendar.MINUTE));
    assertEquals(58, c.get(Calendar.SECOND));
    //assertEquals(0, c.get(Calendar.MILLISECOND));
}

From source file:org.codelibs.fess.taglib.FessFunctions.java

License:Apache License

public static Date parseDate(final String value, final String format) {
    if (value == null) {
        return null;
    }//from   w  w  w  . j a  va 2s  .co m

    try {
        if (PDF_DATE.equals(format)) {
            final Calendar cal = DateConverter.toCalendar(value);
            return cal != null ? cal.getTime() : null;
        }

        final long time = Joda.forPattern(format).parseMillis(value);
        return new Date(time);
    } catch (final Exception e) {
        return null;
    }
}