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

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

Introduction

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

Prototype

public static String format(Date date, String pattern) 

Source Link

Document

Formats a date/time into a specific pattern.

Usage

From source file:eionet.cr.dao.virtuoso.VirtuosoUrgentHarvestQueueDAO.java

/**
 *
 * @param item//from   w  ww .  j a  v a 2  s . c om
 * @throws SQLException
 */
private static int deleteQueueItem(UrgentHarvestQueueItemDTO item, Connection conn) throws SQLException {

    if (item == null || StringUtils.isBlank(item.getUrl()) || item.getTimeAdded() == null) {
        return 0;
    }

    List<Object> values = new ArrayList<Object>();
    values.add(item.getUrl());
    values.add(DateFormatUtils.format(item.getTimeAdded(), "yyyy-MM-dd HH:mm:ss"));

    return SQLUtil.executeUpdate(DELETE_QUEUE_ITEM_SQL, values, conn);
}

From source file:com.qcadoo.localization.api.utils.DateUtils.java

private static String formatDate(final Date date, final String pattern) {
    if (date == null) {
        return "";
    }/*from  w w  w  .  jav a 2 s  .co m*/
    return DateFormatUtils.format(date, pattern);
}

From source file:jlibrtp.RtcpPktSR.java

@Override
public String toString() {
    StringBuilder buf = new StringBuilder();
    buf.append("{RtcpPktSR, ssrc=").append(ssrc);
    buf.append(", numPkt=").append(Long.toString(sendersPktCount));
    buf.append(", octet=").append(Long.toString(sendersOctCount)).append("B");
    buf.append(", ntp=").append(DateFormatUtils.format(getNTPTime(), "yyyy-MM-dd HH:mm:ss.SSS"));
    buf.append(", rtpTs=").append(rtpTs);

    if (null != this.rReports) {
        buf.append(", Part of Sender Report: ").append(rReports);
    }//from   w  ww .java  2  s.  c  o  m

    buf.append("}");
    return buf.toString();
}

From source file:com.sanyanyu.syybi.utils.DateUtils.java

public static String getOffsetMonth(int offset, String pattern) {
    Calendar cal = Calendar.getInstance();
    cal.add(Calendar.MONTH, offset);
    String currentDate = DateFormatUtils.format(cal, pattern);
    return currentDate;
}

From source file:net.opentsdb.core.TsdbQuery.java

private void selectMiddleRows(List<KeyValue> oneList, Vector<String[]> vector, DataType dataType) {
    for (KeyValue kv : oneList) {
        String[] strArray = new String[] { dataType.getData(kv.value()),
                DateFormatUtils.format(
                        new Date((Bytes.getUnsignedInt(kv.key(), tsdb.metrics.width())
                                + (short) (Bytes.getShort(kv.qualifier()) >> Const.FLAG_BITS)) * 1000),
                        DATE_PATTERN) };
        vector.add(strArray);/*from ww w  . j av  a2s.c om*/
    }
}

From source file:com.prowidesoftware.swift.model.field.Field.java

/**
 * @param d Date object to format//  ww  w.  j  a va 2 s. c om
 * @return the formatted date as dd/MM/yyyy or empty if exception occurs during formatting
 */
protected static String format(final Calendar d) {
    try {
        return DateFormatUtils.format(d.getTime(), "dd/MM/yyyy");
    } catch (final Exception ignored) {
        return StringUtils.EMPTY;
    }
}

From source file:com.autonomy.aci.client.services.impl.ErrorProcessorTest.java

@Test
public void testPartialErrorResponse() throws XMLStreamException, AciErrorException, ProcessorException {
    try {//from w ww.j av a2 s  .  co m
        // Execute the processor...
        processor.process(XmlTestUtils.getResourceAsXMLStreamReader(
                "/com/autonomy/aci/client/services/processor/errorProcessorTestPartialErrorResponse.xml"));
        fail("Should have thrown an AciErrorException");
    } catch (final AciErrorException exception) {
        // Check it...
        assertThat("errorId property not as expected.", exception.getErrorId(),
                is(equalTo("AutonomyIDOLServerWOBBLE1")));
        assertThat("rawErrorId property not as expected.", exception.getRawErrorId(), is(nullValue()));
        assertThat("errorString property not as expected.", exception.getErrorString(), is(equalTo("ERROR")));
        assertThat("errorDescription property not as expected.", exception.getErrorDescription(),
                is(equalTo("The requested action was not recognised")));
        assertThat("errorCode property not as expected.", exception.getErrorCode(),
                is(equalTo("ERRORNOTIMPLEMENTED")));
        assertThat("errorTime property not as expected.",
                DateFormatUtils.format(exception.getErrorTime(), "dd MMM yy HH:mm:ss"),
                is(equalTo("06 Feb 06 17:03:54")));
    }
}

From source file:com.autonomy.aci.client.services.impl.DocumentProcessorTest.java

@Test
@SuppressWarnings("unchecked")
public void testCheckACIResponseForErrorWithErrorResponse() throws IOException, ProcessorException {
    try {/*www .  jav  a2  s .  c  o  m*/
        // Setup with a error response file...
        final BasicHttpResponse response = new BasicHttpResponse(HttpVersion.HTTP_1_1, 200, "OK");
        response.setEntity(new InputStreamEntity(getClass().getResourceAsStream("/AciException-1.xml"), -1));

        // Set the AciResponseInputStream...
        final AciResponseInputStream stream = new AciResponseInputStreamImpl(response);

        // Process...
        processor.process(stream);
        fail("Should have raised an AciErrorException.");
    } catch (final AciErrorException aee) {
        // Check its properties...
        assertThat("errorId property not as expected.", aee.getErrorId(),
                is(equalTo("AutonomyIDOLServerWOBBLE1")));
        assertThat("errorString property not as expected.", aee.getErrorString(), is(equalTo("ERROR")));
        assertThat("errorDescription property not as expected.", aee.getErrorDescription(),
                is(equalTo("The requested action was not recognised")));
        assertThat("errorCode property not as expected.", aee.getErrorCode(),
                is(equalTo("ERRORNOTIMPLEMENTED")));
        assertThat("errorTime property not as expected.",
                DateFormatUtils.format(aee.getErrorTime(), "dd MMM yy HH:mm:ss"),
                is(equalTo("06 Feb 06 17:03:54")));
    }
}

From source file:com.netsteadfast.greenstep.bsc.action.HistoryItemScoreReportAction.java

public String getStartDate() {
    Date endDate = DateUtils.addDays(new Date(), -30);
    return DateFormatUtils.format(endDate, "yyyy/MM/dd");
}

From source file:hubert.team.paragraphs.AdvertsOverviewModel.java

private Link getLink(final Calendar monthToShow) {

    return new Link() {
        public String getHref() {
            String newURL = MagnoliaTemplatingUtilities.getInstance()
                    .createLink(MgnlContext.getAggregationState().getMainContent());
            newURL = StringUtils.removeEnd(newURL, ".html");
            newURL = StringUtils.removeEnd(newURL, "." + MgnlContext.getAggregationState().getSelector());
            newURL += DateFormatUtils.format(monthToShow, ".yyyy.MM") + ".html";
            return newURL;
        }//from   w ww.j  a va2  s.  c  o m

        public String getNavigationTitle() {
            return null;
        }

        public String getTitle() {
            return DateFormatUtils.format(monthToShow, "MMMM",
                    I18nContentSupportFactory.getI18nSupport().getLocale());
        }
    };
}