Example usage for org.apache.commons.lang.time DateFormatUtils ISO_DATE_FORMAT

List of usage examples for org.apache.commons.lang.time DateFormatUtils ISO_DATE_FORMAT

Introduction

In this page you can find the example usage for org.apache.commons.lang.time DateFormatUtils ISO_DATE_FORMAT.

Prototype

FastDateFormat ISO_DATE_FORMAT

To view the source code for org.apache.commons.lang.time DateFormatUtils ISO_DATE_FORMAT.

Click Source Link

Document

ISO8601 formatter for date without time zone.

Usage

From source file:MainClass.java

public static void main(String[] args) {
    //Format Date into ISO_DATE_FORMAT
    System.out.println("3) ISO_DATE_FORMAT >>>" + DateFormatUtils.ISO_DATE_FORMAT.format(new Date()));

}

From source file:TimeTrial.java

public static void main(String[] args) {
    // Format Date into dd-MM-yyyy
    System.out.println("1) dd-MM-yyyy >>>" + DateFormatUtils.format(new Date(), "dd-MM-yyyy"));

    // Format Date into SMTP_DATETIME_FORMAT
    System.out.println("2) SMTP_DATETIME_FORMAT >>>" + DateFormatUtils.SMTP_DATETIME_FORMAT.format(new Date()));

    // Format Date into ISO_DATE_FORMAT
    System.out.println("3) ISO_DATE_FORMAT >>>" + DateFormatUtils.ISO_DATE_FORMAT.format(new Date()));

    // Format milliseconds in long
    System.out.println(// ww w  .j  av a2s  .  c o m
            "4) MMM dd yy HH:mm >>>" + DateFormatUtils.format(System.currentTimeMillis(), "MMM dd yy HH:mm"));

    // Format milliseconds in long using UTC timezone
    System.out.println(
            "5) MM/dd/yy HH:mm >>>" + DateFormatUtils.formatUTC(System.currentTimeMillis(), "MM/dd/yy HH:mm"));
}

From source file:com.ikanow.infinit.e.harvest.utils.DateUtility.java

public synchronized static long parseDate(String sDate) {
    if (null == _allowedDatesArray_startsWithLetter) {
        _allowedDatesArray_startsWithLetter = new String[] { DateFormatUtils.SMTP_DATETIME_FORMAT.getPattern(),

                "MMM d, yyyy hh:mm a", "MMM d, yyyy HH:mm", "MMM d, yyyy hh:mm:ss a", "MMM d, yyyy HH:mm:ss",
                "MMM d, yyyy hh:mm:ss.SS a", "MMM d, yyyy HH:mm:ss.SS",

                "EEE MMM dd HH:mm:ss zzz yyyy", "EEE MMM dd yyyy HH:mm:ss zzz",
                "EEE MMM dd yyyy HH:mm:ss 'GMT'Z (zzz)", };
        _allowedDatesArray_numeric_1 = new String[] { "yyyy-MM-dd'T'HH:mm:ss'Z'",
                DateFormatUtils.ISO_DATE_FORMAT.getPattern(),
                DateFormatUtils.ISO_DATE_TIME_ZONE_FORMAT.getPattern(),
                DateFormatUtils.ISO_DATETIME_FORMAT.getPattern(),
                DateFormatUtils.ISO_DATETIME_TIME_ZONE_FORMAT.getPattern() };

        _allowedDatesArray_numeric_2 = new String[] { "yyyyMMdd", "yyyyMMdd hh:mm a", "yyyyMMdd HH:mm",
                "yyyyMMdd hh:mm:ss a", "yyyyMMdd HH:mm:ss", "yyyyMMdd hh:mm:ss.SS a", "yyyyMMdd HH:mm:ss.SS",
                // Julian, these are unlikely
                "yyyyDDD", "yyyyDDD hh:mm a", "yyyyDDD HH:mm", "yyyyDDD hh:mm:ss a", "yyyyDDD HH:mm:ss",
                "yyyyDDD hh:mm:ss.SS a", "yyyyDDD HH:mm:ss.SS", };
        _allowedDatesArray_stringMonth = new String[] { "dd MMM yy", "dd MMM yy hh:mm a", "dd MMM yy HH:mm",
                "dd MMM yy hh:mm:ss a", "dd MMM yy HH:mm:ss", "dd MMM yy hh:mm:ss.SS a",
                "dd MMM yy HH:mm:ss.SS", };
        _allowedDatesArray_numericMonth = new String[] { "MM dd yy", "MM dd yy hh:mm a", "MM dd yy HH:mm",
                "MM dd yy hh:mm:ss a", "MM dd yy HH:mm:ss", "MM dd yy hh:mm:ss.SS a", "MM dd yy HH:mm:ss.SS", };
    }/*from   w  w  w .j av a  2 s  .  c o  m*/

    // Starts with day or month:

    String sDateTmp = sDate;
    if (Character.isLetter(sDate.charAt(0))) {
        try {
            Date date = DateUtils.parseDate(sDate, _allowedDatesArray_startsWithLetter);
            return date.getTime();
        } catch (Exception e) {
        } // keep going         
    } //TESTED
    else if (Character.isLetter(sDate.charAt(5))) {

        // month must be string, doesn't start with day though

        try {
            int index = sDate.indexOf(':');
            if (index > 0) {
                sDate = new StringBuffer(sDate.substring(0, index).replaceAll("[./-]", " "))
                        .append(sDate.substring(index)).toString();
            } else {
                sDate = sDate.replaceAll("[ ./-]", " ");
            }
            Date date = DateUtils.parseDate(sDate, _allowedDatesArray_stringMonth);
            return date.getTime();
        } catch (Exception e) {
        } // keep going                              
    } //TESTED
    else {

        // Starts with a number most likely...

        int n = 0;
        for (; n < 4; ++n) {
            if (!Character.isDigit(sDate.charAt(n))) {
                break;
            }
        }
        if (4 == n) {

            // (Probably starts with a year)            

            // One of the formal formats starting with a year            

            try {
                Date date = DateUtils.parseDate(sDate, _allowedDatesArray_numeric_1);
                return date.getTime();
            } catch (Exception e) {
            } // keep going

            // Something more ad hoc starting with a year                        

            try {
                int index = sDate.indexOf(':');
                if (index > 0) {
                    sDate = new StringBuffer(sDate.substring(0, index).replace("-", ""))
                            .append(sDate.substring(index)).toString();
                } else {
                    sDate = sDate.replace("-", "");
                }
                Date date = DateUtils.parseDate(sDate, _allowedDatesArray_numeric_2);
                return date.getTime();
            } catch (Exception e) {
            } // keep going                     
        } //TESTED

        // Probably starts with a day         

        try {
            int index = sDate.indexOf(':');
            if (index > 0) {
                sDate = new StringBuffer(sDate.substring(0, index).replaceAll("[./-]", " "))
                        .append(sDate.substring(index)).toString();
            } else {
                sDate = sDate.replaceAll("[./-]", " ");
            }
            Date date = DateUtils.parseDate(sDate, _allowedDatesArray_numericMonth);
            return date.getTime();
        } //TESTED
        catch (Exception e) {
        } // keep going                     

    }
    sDate = sDateTmp;

    // If we're here, nothing's worked, try "natural language processing"

    try {
        return Chronic.parse(sDate).getBeginCalendar().getTime().getTime();
    } //TESTED
    catch (Exception e2) {
        // Error all the way out
        throw new RuntimeException("Can't parse: " + sDate);
    } //TESTED
}

From source file:com.hs.mail.imap.schedule.MessageCompressor.java

public void compress(String prop, long timeLimit) {
    Date base = ScheduleUtils.getDateBefore(prop);
    if (base != null) {
        Date start = getStartDate(base);
        if (start != null) {
            Date date = start;//from w  ww  .  j  a  v  a2s.  c  o m
            if (logger.isDebugEnabled()) {
                logger.debug("Compressing directories from " + DateFormatUtils.ISO_DATE_FORMAT.format(start)
                        + " to " + DateFormatUtils.ISO_DATE_FORMAT.format(base));
            }
            while (date.before(base) && System.currentTimeMillis() < timeLimit) {
                compressDirectories(date, timeLimit);
                date = DateUtils.addDays(date, 1);
            }
        }
    }
}

From source file:com.hs.mail.imap.schedule.MessageExpunger.java

private void expungeMailboxes(Map<String, Date> criteria, long timeLimit) {
    for (String name : criteria.keySet()) {
        if (logger.isDebugEnabled()) {
            logger.debug("Expunging messages from " + name + " which are older than "
                    + DateFormatUtils.ISO_DATE_FORMAT.format(criteria.get(name)) + ".");
        }/*from w  ww  .  j a  v  a 2s .  c  om*/
        String mbox = BASE64MailboxEncoder.encode(name);
        List<Long> mailboxIdes = manager.getMailboxIDList(mbox);
        if (CollectionUtils.isNotEmpty(mailboxIdes)) {
            for (Long mailboxID : mailboxIdes) {
                if (System.currentTimeMillis() >= timeLimit) {
                    return;
                }
                expungeMessages(mailboxID, criteria.get(name));
            }
        }
    }
}

From source file:it.qualityGate.QualityGateUiTest.java

/**
 * SONAR-3326/*www  .  ja  v a  2s  .  c  o  m*/
 */
@Test
public void display_alerts_correctly_in_history_page() {
    QualityGateClient qgClient = qgClient();
    QualityGate qGate = qgClient.create("AlertsForHistory");
    qgClient.setDefault(qGate.id());

    String firstAnalysisDate = DateFormatUtils.ISO_DATE_FORMAT.format(addDays(new Date(), -2));
    String secondAnalysisDate = DateFormatUtils.ISO_DATE_FORMAT.format(addDays(new Date(), -1));

    // with this configuration, project should have an Orange alert
    QualityGateCondition lowThresholds = qgClient.createCondition(NewCondition.create(qGate.id())
            .metricKey("lines").operator("GT").warningThreshold("5").errorThreshold("50"));
    scanSampleWithDate(firstAnalysisDate);
    // with this configuration, project should have a Green alert
    qgClient.updateCondition(UpdateCondition.create(lowThresholds.id()).metricKey("lines").operator("GT")
            .warningThreshold("5000").errorThreshold("5000"));
    scanSampleWithDate(secondAnalysisDate);

    ProjectActivityPage page = Navigation.get(orchestrator).openProjectActivity("sample");
    page.assertFirstAnalysisOfTheDayHasText(secondAnalysisDate, "Green (was Orange)")
            .assertFirstAnalysisOfTheDayHasText(firstAnalysisDate, "Orange");

    qgClient.unsetDefault();
    qgClient.destroy(qGate.id());
}

From source file:mitm.common.security.crl.X509CRLEntryInspector.java

/**
 * Returns a string representation of the crlEntry
 *//* ww  w  . j av a2 s  .  com*/
public static String toString(X509CRLEntry crlEntry) {
    Date revocationDate = crlEntry.getRevocationDate();

    String reason;

    try {
        reason = ObjectUtils.toString(getReason(crlEntry), "");
    } catch (IOException e) {
        reason = "";
    }

    return getSerialNumberHex(crlEntry) + "\t"
            + (revocationDate != null ? DateFormatUtils.ISO_DATE_FORMAT.format(revocationDate) : "") + "\t"
            + reason;
}

From source file:com.hs.mail.imap.dao.SearchQuery.java

private static String dateQuery(String field, DateKey key) {
    return String.format("DATE(%s) %s DATE('%s')", field, getOp(key.getComparison()),
            DateFormatUtils.ISO_DATE_FORMAT.format(key.getDate()));
}

From source file:it.dbCleaner.PurgeTest.java

@Test
public void test_evolution_of_number_of_rows_when_scanning_two_times_the_same_project() {
    Date today = new Date();
    Date yesterday = DateUtils.addDays(today, -1);

    scan(PROJECT_SAMPLE_PATH, DateFormatUtils.ISO_DATE_FORMAT.format(yesterday));

    // count components
    collector.checkThat("Wrong number of projects", count("projects where qualifier in ('TRK','BRC')"),
            equalTo(7));/*from  www  . jav a2s  .c  o m*/
    collector.checkThat("Wrong number of directories", count("projects where qualifier in ('DIR')"),
            equalTo(4));
    collector.checkThat("Wrong number of files", count("projects where qualifier in ('FIL')"), equalTo(4));
    collector.checkThat("Wrong number of unit test files", count("projects where qualifier in ('UTS')"),
            equalTo(0));

    int measuresOnTrk = 45;
    int measuresOnBrc = 222;
    int measuresOnDir = 141;
    int measuresOnFil = 69;

    // count measures
    assertMeasuresCountForQualifier("TRK", measuresOnTrk);
    assertMeasuresCountForQualifier("BRC", measuresOnBrc);
    assertMeasuresCountForQualifier("DIR", measuresOnDir);
    assertMeasuresCountForQualifier("FIL", measuresOnFil);

    // No new_* metrics measure should be recorded the first time
    collector.checkThat("Wrong number of measure of new_ metrics", count(
            "project_measures, metrics where metrics.id = project_measures.metric_id and metrics.name like 'new_%'"),
            equalTo(0));

    int expectedMeasures = measuresOnTrk + measuresOnBrc + measuresOnDir + measuresOnFil;
    collector.checkThat("Wrong number of measures", count("project_measures"), equalTo(expectedMeasures));
    collector.checkThat("Wrong number of measure data",
            count("project_measures where measure_data is not null"), equalTo(0));

    // count other tables that are constant between 2 scans
    int expectedIssues = 52;

    collector.checkThat("Wrong number of issues", count("issues"), equalTo(expectedIssues));

    // must be a different date, else a single snapshot is kept per day
    scan(PROJECT_SAMPLE_PATH, DateFormatUtils.ISO_DATE_FORMAT.format(today));

    int newMeasuresOnTrk = 58;
    int newMeasuresOnBrc = 304;
    int newMeasuresOnDir = 56;
    int newMeasuresOnFil = 0;

    assertMeasuresCountForQualifier("TRK", measuresOnTrk + newMeasuresOnTrk);
    assertMeasuresCountForQualifier("BRC", measuresOnBrc + newMeasuresOnBrc);
    assertMeasuresCountForQualifier("DIR", measuresOnDir + newMeasuresOnDir);
    assertMeasuresCountForQualifier("FIL", measuresOnFil + newMeasuresOnFil);

    // Measures on new_* metrics should be recorded
    collector.checkThat("Wrong number of measure of new_ metrics", count(
            "project_measures, metrics where metrics.id = project_measures.metric_id and metrics.name like 'new_%'"),
            equalTo(154));

    // added measures relate to project and new_* metrics
    expectedMeasures += newMeasuresOnTrk + newMeasuresOnBrc + newMeasuresOnDir + newMeasuresOnFil;
    collector.checkThat("Wrong number of measures after second analysis", count("project_measures"),
            equalTo(expectedMeasures));
    collector.checkThat("Wrong number of measure data",
            count("project_measures where measure_data is not null"), equalTo(0));
    collector.checkThat("Wrong number of issues", count("issues"), equalTo(expectedIssues));
}

From source file:de.extra.client.plugins.outputplugin.mtomws.WsCxfIT.java

private void saveAttachment(final ResponseTransport responseTransport) throws IOException {
    final DataHandler dataHandler = responseTransport.getTransportBody().getData().getBase64CharSequence()
            .getValue();//  w  ww.  j  ava  2s.  co  m
    final File receivedFile = new File(outputDirectory,
            "tempClientInput" + DateFormatUtils.ISO_DATE_FORMAT.format(new Date()) + ".txt");

    final FileOutputStream fileOutputStream = new FileOutputStream(receivedFile);
    IOUtils.copyLarge(dataHandler.getInputStream(), fileOutputStream);
    logger.info("Attachment saved into " + receivedFile.getAbsolutePath());
}