Example usage for org.apache.commons.lang.time FastDateFormat SHORT

List of usage examples for org.apache.commons.lang.time FastDateFormat SHORT

Introduction

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

Prototype

int SHORT

To view the source code for org.apache.commons.lang.time FastDateFormat SHORT.

Click Source Link

Document

SHORT locale dependent date or time style.

Usage

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

/**
 * Uses the current locale (user) to format the date and time
 * @param val Date or Calendar/*from   www.j  a  va  2 s  .c o  m*/
 * @return the String
 */
public static String formatDateTime(Object val) {
    FastDateFormat format = FastDateFormat.getDateTimeInstance(FastDateFormat.SHORT, FastDateFormat.SHORT,
            MgnlContext.getLocale());
    return format.format(val);
}

From source file:com.benfante.minimark.blo.AssessmentXMLFOBuilder.java

private StringBuilder makeHeader(StringBuilder result, AssessmentFilling assessment, Locale locale) {
    FastDateFormat dateTimeFormat = FastDateFormat.getDateTimeInstance(FastDateFormat.SHORT,
            FastDateFormat.SHORT, locale);
    result.append("<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>").append('\n');
    result.append("<!DOCTYPE root [").append('\n');
    result.append("  <!ELEMENT root (#PCDATA) >").append('\n');
    result.append(//w  ww.  j a  va  2s.c  om
            "    <!ENTITY rchk '<fo:external-graphic src=\"url(&apos;images/interface/rchk.gif&apos;)\" content-height=\"9pt\" content-width=\"9pt\"/>' >")
            .append('\n');
    result.append(
            "    <!ENTITY ruchk '<fo:external-graphic src=\"url(&apos;images/interface/ruchk.gif&apos;)\" content-height=\"9pt\" content-width=\"9pt\"/>' >")
            .append('\n');
    result.append(
            "    <!ENTITY cchk '<fo:external-graphic src=\"url(&apos;images/interface/cchk.jpg&apos;)\" content-height=\"9pt\" content-width=\"9pt\"/>' >")
            .append('\n');
    result.append(
            "    <!ENTITY cuchk '<fo:external-graphic src=\"url(&apos;images/interface/cuchk.jpg&apos;)\" content-height=\"9pt\" content-width=\"9pt\"/>' >")
            .append('\n');
    result.append("    <!ENTITY agrave '&#xe0;' >").append('\n');
    result.append("    <!ENTITY egrave '&#xe8;' >").append('\n');
    result.append("    <!ENTITY igrave '&#xec;' >").append('\n');
    result.append("    <!ENTITY ograve '&#xf2;' >").append('\n');
    result.append("    <!ENTITY ugrave '&#xf9;' >").append('\n');
    result.append("    <!ENTITY aacute '&#xe1;' >").append('\n');
    result.append("    <!ENTITY eacute '&#xe9;' >").append('\n');
    result.append("    <!ENTITY iacute '&#xed;' >").append('\n');
    result.append("    <!ENTITY oacute '&#xf3;' >").append('\n');
    result.append("    <!ENTITY uacute '&#xfa;' >").append('\n');
    result.append("]>").append('\n');
    result.append("<fo:root xmlns:fo=\"http://www.w3.org/1999/XSL/Format\">").append('\n');
    result.append("  <fo:layout-master-set>").append('\n');
    result.append(
            "    <fo:simple-page-master master-name=\"normal\" page-height=\"210mm\" page-width=\"297mm\" margin-top=\"1cm\" margin-bottom=\"0.5cm\" margin-left=\"1.5cm\" margin-right=\"1.5cm\">")
            .append('\n');
    result.append(
            "      <fo:region-body margin-top=\"0cm\" margin-bottom=\"1.5cm\" column-count=\"2\" column-gap=\"0.25in\"/>")
            .append('\n');
    result.append("      <fo:region-before extent=\"0cm\"/>").append('\n');
    result.append("      <fo:region-after extent=\"1cm\"/>").append('\n');
    result.append("    </fo:simple-page-master>").append('\n');

    result.append(
            "    <fo:simple-page-master master-name=\"blank\" page-height=\"210mm\" page-width=\"297mm\" margin-top=\"1cm\" margin-bottom=\"0.5cm\" margin-left=\"1.5cm\" margin-right=\"1.5cm\">")
            .append('\n');
    result.append("      <fo:region-body/>").append('\n');
    result.append("      <fo:region-before region-name=\"header-blank\" extent=\"297mm\"/>").append('\n');
    result.append("      <fo:region-after extent=\"1cm\"/>").append('\n');
    result.append("    </fo:simple-page-master>").append('\n');
    result.append("    <fo:page-sequence-master master-name=\"all\">").append('\n');
    result.append("      <fo:repeatable-page-master-alternatives>").append('\n');
    result.append(
            "        <fo:conditional-page-master-reference blank-or-not-blank=\"not-blank\" master-reference=\"normal\"/>")
            .append('\n');
    result.append(
            "        <fo:conditional-page-master-reference blank-or-not-blank=\"blank\" master-reference=\"blank\"/>")
            .append('\n');
    result.append("      </fo:repeatable-page-master-alternatives>").append('\n');
    result.append("    </fo:page-sequence-master>").append('\n');

    result.append("  </fo:layout-master-set>").append('\n');
    result.append(
            "  <fo:page-sequence id=\"assprintseq\" master-reference=\"all\" font-family=\"sans-serif\" font-size=\"9pt\" line-height=\"11pt\" space-after.optimum=\"12pt\" force-page-count=\"end-on-even\">")
            .append('\n');

    result.append("    <fo:static-content flow-name=\"header-blank\">");
    result.append("      <fo:block space-before=\"100mm\" text-align-last=\"center\">").append(
            messageSource.getMessage("IntentionallyLeftBlank", null, "?IntentionallyLeftBlank?", locale))
            .append("</fo:block>");
    result.append("    </fo:static-content>");

    result.append("    <fo:static-content flow-name=\"xsl-region-after\">").append('\n');
    result.append("      <fo:block>").append('\n');
    result.append("        <fo:table table-layout=\"fixed\" width=\"264mm\">").append('\n');
    result.append("          <fo:table-column column-width=\"88mm\"/>").append('\n');
    result.append("          <fo:table-column column-width=\"88mm\"/>").append('\n');
    result.append("          <fo:table-column column-width=\"88mm\"/>").append('\n');
    result.append("          <fo:table-body>").append('\n');
    result.append("            <fo:table-row>").append('\n');
    result.append("              <fo:table-cell text-align=\"start\">").append('\n');
    result.append("                <fo:block>").append('\n');
    result.append("                  <![CDATA[").append(assessment.getIdentifier()).append(' ')
            .append(assessment.getFirstName()).append(' ').append(assessment.getLastName()).append("]]>")
            .append('\n');
    result.append("                </fo:block>").append('\n');
    result.append("              </fo:table-cell>").append('\n');
    result.append("              <fo:table-cell text-align=\"center\">").append('\n');
    result.append("                <fo:block>").append('\n');
    result.append("                  ")
            .append(assessment.getSubmittedDate() != null ? dateTimeFormat.format(assessment.getSubmittedDate())
                    : messageSource.getMessage("NotSubmitted", null, "?NotSubmitted?", locale))
            .append('\n');
    result.append("                </fo:block>").append('\n');
    result.append("              </fo:table-cell>").append('\n');
    result.append("              <fo:table-cell text-align=\"end\">").append('\n');
    result.append("                <fo:block>").append('\n');
    result.append(messageSource.getMessage("PageNOfM",
            new String[] { "<fo:page-number/>", "<fo:page-number-citation-last ref-id='assprintseq'/>" },
            "?PageNOfM?", locale)).append('\n');
    result.append("                </fo:block>").append('\n');
    result.append("              </fo:table-cell>").append('\n');
    result.append("            </fo:table-row>").append('\n');
    result.append("          </fo:table-body>").append('\n');
    result.append("        </fo:table>").append('\n');
    result.append("      </fo:block>").append('\n');
    result.append("    </fo:static-content>").append('\n');
    result.append("    <fo:flow flow-name=\"xsl-region-body\">").append('\n');
    result.append("      <fo:block font-size=\"11pt\" font-weight=\"bold\" text-align=\"center\">")
            .append('\n');
    result.append("        <fo:block space-after=\"11pt\">").append(assessment.getAssessment().getTitle())
            .append("</fo:block>").append('\n');
    result.append("        <fo:block>")
            .append(messageSource.getMessage("Incumbent", null, "?Incumbent?", locale)).append(": ")
            .append(assessment.getAssessment().getCourse().getIncumbent()).append("</fo:block>").append('\n');
    result.append("        <fo:block>").append(dateTimeFormat.format(assessment.getStartDate()))
            .append("</fo:block>").append('\n');
    result.append("      </fo:block>").append('\n');
    return result;
}

From source file:edu.ku.brc.specify.tests.PreferenceTest.java

/**
 * Tests the Date formating//w ww  .jav  a2  s .c  om
 */
public void testSimpleDateFormat() {
    FastDateFormat fastDateFormat = FastDateFormat.getDateInstance(FastDateFormat.SHORT);
    SimpleDateFormat df = new SimpleDateFormat(fastDateFormat.getPattern());
    log.info(df.toPattern());
    log.info(df.format(new Date()));

    fastDateFormat = FastDateFormat.getDateInstance(FastDateFormat.MEDIUM);
    df = new SimpleDateFormat(fastDateFormat.getPattern());
    log.info(df.toPattern());
    log.info(df.format(new Date()));

    fastDateFormat = FastDateFormat.getDateInstance(FastDateFormat.LONG);
    df = new SimpleDateFormat(fastDateFormat.getPattern());
    log.info(df.toPattern());
    log.info(df.format(new Date()));
}

From source file:info.magnolia.jcr.util.PropertyUtil.java

public static String getDateFormat() {
    try {//from  w w  w  . ja va  2  s.  com
        return FastDateFormat.getDateInstance(FastDateFormat.SHORT, MgnlContext.getLocale()).getPattern();
    } catch (IllegalStateException e) {
        // this happens if the context is not (yet) set
        return DateUtil.YYYY_MM_DD;
    }
}