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

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

Introduction

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

Prototype

public static String formatUTC(Date date, String pattern) 

Source Link

Document

Formats a date/time into a specific pattern using the UTC time zone.

Usage

From source file:MainClass.java

public static void main(String[] pArgs) throws Exception {
    Date now = new Date();
    System.out.println("now: " + DateFormatUtils.ISO_DATETIME_TIME_ZONE_FORMAT.format(now));
    System.out.println("UTC Time: "
            + DateFormatUtils.formatUTC(now, DateFormatUtils.ISO_DATETIME_TIME_ZONE_FORMAT.getPattern()));

}

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(/* w  w  w.  j  a  v  a  2s . co  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.iflytek.kcloud.web.utils.BookDateUtil.java

/**
 *  ?yyyy-MM-dd pattern?"yyyy-MM-dd" "HH:mm:ss" "E"
 *///from   www  .  j  av a 2s  .  c  o m
public static String formatUTCDate(Date date, Object... pattern) {
    String formatDate = null;
    if (pattern != null && pattern.length > 0) {
        formatDate = DateFormatUtils.formatUTC(date, pattern[0].toString());
    } else {
        formatDate = DateFormatUtils.formatUTC(date, "yyyy-MM-dd");
    }
    return formatDate;
}

From source file:info.magnolia.cms.util.DateUtil.java

public String getFormattedDate(Date date, String formatPattern) {
    if (formatPattern == null) {
        formatPattern = FORMAT_DEFAULTPATTERN;
    }//from  w  w  w . ja  v a  2s.  com
    return DateFormatUtils.formatUTC(date, formatPattern);
}

From source file:de.fhg.iais.commons.time.StopWatch.java

public String stopTime() {
    return DateFormatUtils.formatUTC(stop(), DateFormatUtils.ISO_TIME_NO_T_FORMAT.getPattern());
}

From source file:com.hybris.datahub.core.util.OutboundServiceCsvUtilsUnitTest.java

@Test
public void testGetStringValueOfObject_ShouldFormatDates() {
    final Date date = new Date();
    final String formattedDate = csvUtils.getStringValueOfObject(date);

    Assert.assertEquals(DateFormatUtils.formatUTC(date, DEFAULT_DATE_FORMAT), formattedDate);
}

From source file:com.ecyrd.jspwiki.rss.AtomFeed.java

private Collection getItems() {
    ArrayList<Element> list = new ArrayList<Element>();

    WikiEngine engine = m_wikiContext.getEngine();
    ServletContext servletContext = null;

    if (m_wikiContext.getHttpRequest() != null)
        servletContext = m_wikiContext.getHttpRequest().getSession().getServletContext();

    for (Iterator i = m_entries.iterator(); i.hasNext();) {
        Entry e = (Entry) i.next();//from  w  w  w . ja  v a 2s. c  o  m

        WikiPage p = e.getPage();

        Element entryEl = getElement("entry");

        //
        //  Mandatory elements
        //

        entryEl.addContent(getElement("id").setText(getEntryID(e)));
        entryEl.addContent(getElement("title").setAttribute("type", "html").setText(e.getTitle()));
        entryEl.addContent(
                getElement("updated").setText(DateFormatUtils.formatUTC(p.getLastModified(), RFC3339FORMAT)));
        //
        //  Optional elements
        //

        entryEl.addContent(getElement("author").addContent(getElement("name").setText(e.getAuthor())));
        entryEl.addContent(
                getElement("link").setAttribute("rel", "alternate").setAttribute("href", e.getURL()));
        entryEl.addContent(getElement("content").setAttribute("type", "html").setText(e.getContent()));

        //
        //  Check for enclosures
        //

        if (engine.getAttachmentManager().hasAttachments(p) && servletContext != null) {
            try {
                Collection c = engine.getAttachmentManager().listAttachments(p);

                for (Iterator a = c.iterator(); a.hasNext();) {
                    Attachment att = (Attachment) a.next();

                    Element attEl = getElement("link");
                    attEl.setAttribute("rel", "enclosure");
                    attEl.setAttribute("href", engine.getURL(WikiContext.ATTACH, att.getName(), null, true));
                    attEl.setAttribute("length", Long.toString(att.getSize()));
                    attEl.setAttribute("type", getMimeType(servletContext, att.getFileName()));

                    entryEl.addContent(attEl);
                }
            } catch (ProviderException ex) {
                // FIXME: log.info("Can't get attachment data",ex);
            }
        }

        list.add(entryEl);
    }

    return list;
}

From source file:com.discursive.jccook.lang.DateFormatExample.java

public void testFormatUTC() throws Exception {
    Date now = new Date();
    logger.debug("now: " + DateFormatUtils.ISO_DATETIME_TIME_ZONE_FORMAT.format(now));
    logger.debug("UTC Time: "
            + DateFormatUtils.formatUTC(now, DateFormatUtils.ISO_DATETIME_TIME_ZONE_FORMAT.getPattern()));

}

From source file:com.ecyrd.jspwiki.rss.AtomFeed.java

/**
 *  {@inheritDoc}//from  w w  w.  j a  va 2s  . c om
 */
@Override
public String getString() {
    Element root = getElement("feed");
    WikiEngine engine = m_wikiContext.getEngine();

    Date lastModified = new Date(0L);

    for (Iterator i = m_entries.iterator(); i.hasNext();) {
        Entry e = (Entry) i.next();

        if (e.getPage().getLastModified().after(lastModified))
            lastModified = e.getPage().getLastModified();
    }

    //
    //  Mandatory parts
    //
    root.addContent(getElement("title").setText(getChannelTitle()));
    root.addContent(getElement("id").setText(getFeedID()));
    root.addContent(getElement("updated").setText(DateFormatUtils.formatUTC(lastModified, RFC3339FORMAT)));

    //
    //  Optional
    //
    // root.addContent( getElement("author").addContent(getElement("name").setText(format())))
    root.addContent(getElement("link").setAttribute("href", engine.getBaseURL()));
    root.addContent(getElement("generator").setText("JSPWiki " + Release.VERSTR));

    String rssFeedURL = engine.getURL(WikiContext.NONE, "rss.jsp",
            "page=" + engine.encodeName(m_wikiContext.getPage().getName()) + "&mode=" + m_mode + "&type=atom",
            true);
    Element self = getElement("link").setAttribute("rel", "self");
    self.setAttribute("href", rssFeedURL);
    root.addContent(self);

    //
    //  Items
    //

    root.addContent(getItems());

    //
    //  aaand output
    //
    XMLOutputter output = new XMLOutputter();

    output.setFormat(Format.getPrettyFormat());

    try {
        StringWriter res = new StringWriter();
        output.output(root, res);

        return res.toString();
    } catch (IOException e) {
        return null;
    }
}

From source file:info.magnolia.cms.taglibs.Out.java

/**
 * @see javax.servlet.jsp.tagext.Tag#doEndTag()
 *//*from  ww  w  .j a v  a 2 s .  c o m*/
public int doEndTag() {
    // don't reset any value set using a tag attribute here, or it will break any container that does tag pooling!

    Content contentNode = getFirtMatchingNode();
    if (contentNode == null) {
        return EVAL_PAGE;
    }

    NodeData nodeData = contentNode.getNodeData(this.nodeDataName);

    if (!nodeData.isExist()) {
        return EVAL_PAGE;
    }

    String value = null;
    int type = nodeData.getType();

    switch (type) {
    case PropertyType.DATE:

        Date date = nodeData.getDate().getTime();
        if (date != null) {
            if (this.dateLanguage == null) {
                value = DateFormatUtils.formatUTC(date, this.datePattern);
            } else {
                value = DateFormatUtils.formatUTC(date, this.datePattern, new Locale(this.dateLanguage));
            }
        }
        break;

    case PropertyType.BINARY:
        value = this.getFilePropertyValue(contentNode);
        break;

    default:
        value = StringUtils.isEmpty(this.lineBreak) ? nodeData.getString() : nodeData.getString(this.lineBreak);
        // replace internal links
        value = LinkUtil.convertUUIDsToRelativeLinks(value,
                Resource.getActivePage((HttpServletRequest) pageContext.getRequest())); // static actpage
        break;
    }

    if (var != null) {
        // set result as a variable
        pageContext.setAttribute(var, value, scope);
    } else if (value != null) {
        JspWriter out = pageContext.getOut();
        try {
            out.print(value);
        } catch (IOException e) {
            // should never happen
            throw new NestableRuntimeException(e);
        }
    }

    return EVAL_PAGE;
}