Example usage for java.text DateFormat LONG

List of usage examples for java.text DateFormat LONG

Introduction

In this page you can find the example usage for java.text DateFormat LONG.

Prototype

int LONG

To view the source code for java.text DateFormat LONG.

Click Source Link

Document

Constant for long style pattern.

Usage

From source file:org.apache.zookeeper.server.persistence.TxnLogToolkit.java

private void printTxn(byte[] bytes, String prefix) throws IOException {
    TxnHeader hdr = new TxnHeader();
    Record txn = SerializeUtils.deserializeTxn(bytes, hdr);
    String txnStr = getDataStrFromTxn(txn);
    String txns = String.format("%s session 0x%s cxid 0x%s zxid 0x%s %s %s",
            DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.LONG).format(new Date(hdr.getTime())),
            Long.toHexString(hdr.getClientId()), Long.toHexString(hdr.getCxid()),
            Long.toHexString(hdr.getZxid()), TraceFormatter.op2String(hdr.getType()), txnStr);
    if (prefix != null && !"".equals(prefix.trim())) {
        System.out.print(prefix + " - ");
    }//from ww w  .  ja va2s  .  c o  m
    if (txns.endsWith("\n")) {
        System.out.print(txns);
    } else {
        System.out.println(txns);
    }
}

From source file:org.agiso.tempel.Tempel.java

/**
 * /*from   w  w w  .ja v  a 2 s  .  co  m*/
 * 
 * @param properties
 * @throws Exception 
 */
private Map<String, Object> addRuntimeProperties(Map<String, Object> properties) throws Exception {
    Map<String, Object> props = new HashMap<String, Object>();

    // Okrelanie lokalizacji daty/czasu uywanej do wypenienia paramtrw szablonw
    // zawierajcych dat/czas w formatach DateFormat.SHORT, .MEDIUM, .LONG i .FULL:
    Locale date_locale;
    if (properties.containsKey(UP_DATE_LOCALE)) {
        date_locale = LocaleUtils.toLocale((String) properties.get(UP_DATE_LOCALE));
        Locale.setDefault(date_locale);
    } else {
        date_locale = Locale.getDefault();
    }

    TimeZone time_zone;
    if (properties.containsKey(UP_TIME_ZONE)) {
        time_zone = TimeZone.getTimeZone((String) properties.get(UP_DATE_LOCALE));
        TimeZone.setDefault(time_zone);
    } else {
        time_zone = TimeZone.getDefault();
    }

    // Wyznaczanie daty, na podstawie ktrej zostan wypenione parametry szablonw
    // przechowujce dat/czas w formatach DateFormat.SHORT, .MEDIUM, .LONG i .FULL.
    // Odbywa si w oparciu o wartoci parametrw 'date_format' i 'date'. Parametr
    // 'date_format' definiuje format uywany do parsowania acucha reprezentujcego
    // dat okrelon parametrem 'date'. Parametr 'date_format' moe nie by okrelony.
    // W takiej sytuacji uyty jest format DateFormat.LONG aktywnej lokalizacji (tj.
    // systemowej, ktra moe by przedefiniowana przez parametr 'date_locale'), ktry
    // moe by przedefiniowany przez parametry 'date_format_long' i 'time_format_long':
    Calendar calendar = Calendar.getInstance(date_locale);
    if (properties.containsKey(RP_DATE)) {
        String date_string = (String) properties.get(RP_DATE);
        if (properties.containsKey(RP_DATE_FORMAT)) {
            String date_format = (String) properties.get(RP_DATE_FORMAT);
            DateFormat formatter = new SimpleDateFormat(date_format);
            formatter.setTimeZone(time_zone);
            calendar.setTime(formatter.parse(date_string));
        } else if (properties.containsKey(UP_DATE_FORMAT_LONG) && properties.containsKey(UP_TIME_FORMAT_LONG)) {
            // TODO: Zaoenie, e format data-czas jest zoony z acucha daty i czasu rozdzelonych spacj:
            // 'UP_DATE_FORMAT_LONG UP_TIME_FORMAT_LONG'
            DateFormat formatter = new SimpleDateFormat((String) properties.get(UP_DATE_FORMAT_LONG) + " "
                    + (String) properties.get(UP_TIME_FORMAT_LONG), date_locale);
            formatter.setTimeZone(time_zone);
            calendar.setTime(formatter.parse(date_string));
        } else {
            DateFormat formatter = DateFormat.getDateTimeInstance(DateFormat.LONG, DateFormat.LONG,
                    date_locale);
            formatter.setTimeZone(time_zone);
            calendar.setTime(formatter.parse(date_string));
        }
    }

    // Jeli nie okrelono, wypenianie parametrw przechowujcych poszczeglne
    // skadniki daty, tj. rok, miesic i dzie:
    if (!properties.containsKey(TP_YEAR)) {
        props.put(TP_YEAR, calendar.get(Calendar.YEAR));
    }
    if (!properties.containsKey(TP_MONTH)) {
        props.put(TP_MONTH, calendar.get(Calendar.MONTH));
    }
    if (!properties.containsKey(TP_DAY)) {
        props.put(TP_DAY, calendar.get(Calendar.DAY_OF_MONTH));
    }

    // Jeli nie okrelono, wypenianie parametrw przechowujcych dat i czas w
    // formatach SHORT, MEDIUM, LONG i FULL (na podstawie wyznaczonej lokalizacji):
    Date date = calendar.getTime();
    if (!properties.containsKey(TP_DATE_SHORT)) {
        DateFormat formatter;
        if (properties.containsKey(UP_DATE_FORMAT_SHORT)) {
            formatter = new SimpleDateFormat((String) properties.get(UP_DATE_FORMAT_SHORT), date_locale);
        } else {
            formatter = DateFormat.getDateInstance(DateFormat.SHORT, date_locale);
        }
        formatter.setTimeZone(time_zone);
        props.put(TP_DATE_SHORT, formatter.format(date));
    }
    if (!properties.containsKey(TP_DATE_MEDIUM)) {
        DateFormat formatter;
        if (properties.containsKey(UP_DATE_FORMAT_MEDIUM)) {
            formatter = new SimpleDateFormat((String) properties.get(UP_DATE_FORMAT_MEDIUM), date_locale);
        } else {
            formatter = DateFormat.getDateInstance(DateFormat.MEDIUM, date_locale);
        }
        formatter.setTimeZone(time_zone);
        props.put(TP_DATE_MEDIUM, formatter.format(date));
    }
    if (!properties.containsKey(TP_DATE_LONG)) {
        DateFormat formatter;
        if (properties.containsKey(UP_DATE_FORMAT_LONG)) {
            formatter = new SimpleDateFormat((String) properties.get(UP_DATE_FORMAT_LONG), date_locale);
        } else {
            formatter = DateFormat.getDateInstance(DateFormat.LONG, date_locale);
        }
        formatter.setTimeZone(time_zone);
        props.put(TP_DATE_LONG, formatter.format(date));
    }
    if (!properties.containsKey(TP_DATE_FULL)) {
        DateFormat formatter;
        if (properties.containsKey(UP_DATE_FORMAT_FULL)) {
            formatter = new SimpleDateFormat((String) properties.get(UP_DATE_FORMAT_FULL), date_locale);
        } else {
            formatter = DateFormat.getDateInstance(DateFormat.FULL, date_locale);
        }
        formatter.setTimeZone(time_zone);
        props.put(TP_DATE_FULL, formatter.format(date));
    }

    if (!properties.containsKey(TP_TIME_SHORT)) {
        DateFormat formatter;
        if (properties.containsKey(UP_TIME_FORMAT_SHORT)) {
            formatter = new SimpleDateFormat((String) properties.get(UP_TIME_FORMAT_SHORT), date_locale);
        } else {
            formatter = DateFormat.getTimeInstance(DateFormat.SHORT, date_locale);
        }
        formatter.setTimeZone(time_zone);
        props.put(TP_TIME_SHORT, formatter.format(date));
    }
    if (!properties.containsKey(TP_TIME_MEDIUM)) {
        DateFormat formatter;
        if (properties.containsKey(UP_TIME_FORMAT_MEDIUM)) {
            formatter = new SimpleDateFormat((String) properties.get(UP_TIME_FORMAT_MEDIUM), date_locale);
        } else {
            formatter = DateFormat.getTimeInstance(DateFormat.MEDIUM, date_locale);
        }
        formatter.setTimeZone(time_zone);
        props.put(TP_TIME_MEDIUM, formatter.format(date));
    }
    if (!properties.containsKey(TP_TIME_LONG)) {
        DateFormat formatter;
        if (properties.containsKey(UP_TIME_FORMAT_LONG)) {
            formatter = new SimpleDateFormat((String) properties.get(UP_TIME_FORMAT_LONG), date_locale);
        } else {
            formatter = DateFormat.getTimeInstance(DateFormat.LONG, date_locale);
        }
        formatter.setTimeZone(time_zone);
        props.put(TP_TIME_LONG, formatter.format(date));
    }
    if (!properties.containsKey(TP_TIME_FULL)) {
        DateFormat formatter;
        if (properties.containsKey(UP_TIME_FORMAT_FULL)) {
            formatter = new SimpleDateFormat((String) properties.get(UP_TIME_FORMAT_FULL), date_locale);
        } else {
            formatter = DateFormat.getTimeInstance(DateFormat.FULL, date_locale);
        }
        formatter.setTimeZone(time_zone);
        props.put(TP_TIME_FULL, formatter.format(date));
    }

    return props;
}

From source file:org.squale.squaleweb.util.SqualeWebActionUtils.java

/**
 * Retourne une chaine formattant la date.
 * //from   www  .  ja v a 2 s  .  c o m
 * @param pDate la date  formatter.
 * @param lang langue d'affichage
 * @return une chaine reprsantant le date.
 */
public static String getFormattedDate(Date pDate, Locale lang) {
    DateFormat df = DateFormat.getDateInstance(DateFormat.LONG, lang);
    return df.format(pDate);
}

From source file:org.eclipse.ebr.maven.AboutFilesUtil.java

public void generateAboutHtmlFile(final SortedMap<Artifact, Model> dependencies, final File outputDirectory)
        throws MojoExecutionException {
    final File aboutHtmlFile = new File(outputDirectory, ABOUT_HTML);
    if (aboutHtmlFile.isFile() && !isForce()) {
        getLog().warn(format("Found existing about.html file at '%s'. %s", aboutHtmlFile,
                REQUIRES_FORCE_TO_OVERRIDE_MESSAGE));
        return;//  w w w . j ava  2  s .c  om
    }

    String aboutHtmlText = readAboutHtmlTemplate();
    aboutHtmlText = StringUtils.replaceEach(aboutHtmlText, new String[] { // @formatter:off
            "@DATE@", "@THIRD_PARTY_INFO@" },
            new String[] { DateFormat.getDateInstance(DateFormat.LONG, Locale.US).format(new Date()),
                    getThirdPartyInfo(dependencies, outputDirectory) });
    // @formatter:on

    try {
        FileUtils.writeStringToFile(aboutHtmlFile, aboutHtmlText, UTF_8);
    } catch (final IOException e) {
        getLog().debug(e);
        throw new MojoExecutionException(
                format("Unable to write about.html file '%s'. %s", aboutHtmlFile, e.getMessage()));
    }
}

From source file:org.jahia.services.render.URLResolver.java

private Date getVersionDate(HttpServletRequest req) {
    // we assume here that the date has been passed as milliseconds.
    String msString = req.getParameter("v");
    if (msString == null) {
        return null;
    }//from www .j  ava 2s  .  co  m
    try {
        long msLong = Long.parseLong(msString);
        if (logger.isDebugEnabled()) {
            logger.debug("Display version of date : " + SimpleDateFormat
                    .getDateTimeInstance(DateFormat.LONG, DateFormat.LONG).format(new Date(msLong)));
        }
        return new Date(msLong);
    } catch (NumberFormatException nfe) {
        logger.warn("Invalid version date found in URL " + msString);
        return null;
    }
}

From source file:net.sourceforge.dvb.projectx.common.Common.java

/**
 * //from   w  w  w. j  a v  a2s  .  c  o m
 */
public static String getDateAndTime() {
    return (DateFormat.getDateInstance(DateFormat.LONG).format(new Date()) + "    "
            + DateFormat.getTimeInstance(DateFormat.LONG).format(new Date()));
}

From source file:org.lilyproject.runtime.cli.LilyRuntimeCli.java

private void printStartedMessage() {
    DateFormat dateFormat = DateFormat.getDateTimeInstance(DateFormat.LONG, DateFormat.LONG);
    String now = dateFormat.format(new Date());
    infolog.info("Lily Runtime started [" + now + "]");
}

From source file:DDTDate.java

/**
 * This function will populate the varsMap with new copies of values related to display format of date & time stamps.
 * Those values are based on the class (static) date variable that is currently in use.
 * Those values can later be used in verification of UI elements that are date-originated but may change in time (say, today's date, month, year - etc.)
 * The base date that is used is Locale dependent (currently, the local is assumed to be that of the workstation running the software.)
 * When relevant, values are provided in various styles (SHORT, MEDIUM, LONG, FULL) - not all date elements have all those versions available.
 * The purpose of this 'exercise' is to set up the facility for the user to verify any component of date / time stamps independently of one another or 'traditional' formatting.
 *
 * The variables maintained here are formatted with a prefix to distinguish them from other, user defined variables.
 *
 * @TODO: enable Locale modifications (at present the test machine's locale is considered and within a test session only one locale can be tested)
 * @param varsMap//from   w w w  .  j a  v  a  2  s  .  c om
 */
private void maintainDateProperties(Hashtable<String, Object> varsMap) throws Exception {

    String prefix = "$";

    try {
        // Build formatting objects for each of the output styles
        DateFormat shortStyleFormatter = DateFormat.getDateInstance(DateFormat.SHORT);
        DateFormat mediumStyleFormatter = DateFormat.getDateInstance(DateFormat.MEDIUM);
        DateFormat longStyleFormatter = DateFormat.getDateInstance(DateFormat.LONG);
        DateFormat fullStyleFormatter = DateFormat.getDateInstance(DateFormat.FULL);

        // Use a dedicated variable to hold values of formatting results to facilitate debugging
        // @TODO (maybe) when done debugging - convert to inline calls to maintainDateProperty ...
        String formatValue;

        // Examples reflect time around midnight of February 6 2014 - actual values DO NOT include quotes (added here for readability)

        MutableDateTime theReferenceDate = getReferenceDate(); //getReferenceDateAdjustedForTimeZone();
        // Default Date using DDTSettings pattern.
        formatValue = new SimpleDateFormat(defaultDateFormat()).format(theReferenceDate.toDate());
        maintainDateProperty(prefix + "defaultDate", formatValue, varsMap);

        // Short Date - '2/6/14'
        formatValue = shortStyleFormatter.format(theReferenceDate.toDate());
        maintainDateProperty(prefix + "shortDate", formatValue, varsMap);

        // Medium Date - 'Feb 6, 2014'
        formatValue = mediumStyleFormatter.format(theReferenceDate.toDate());
        maintainDateProperty(prefix + "mediumDate", formatValue, varsMap);

        // Long Date - 'February 6, 2014'
        formatValue = longStyleFormatter.format(theReferenceDate.toDate());
        maintainDateProperty(prefix + "longDate", formatValue, varsMap);

        // Full Date 'Thursday, February 6, 2014'
        formatValue = fullStyleFormatter.format(theReferenceDate.toDate());
        maintainDateProperty(prefix + "fullDate", formatValue, varsMap);

        // hours : minutes : seconds : milliseconds (broken to separate components)  -
        formatValue = theReferenceDate.toString("hh:mm:ss:SSS");
        if (formatValue.toString().contains(":")) {
            String[] hms = split(formatValue.toString(), ":");
            if (hms.length > 3) {
                // Hours - '12'
                formatValue = hms[0];
                maintainDateProperty(prefix + "hours", formatValue, varsMap);
                // Minutes - '02'
                formatValue = hms[1];
                maintainDateProperty(prefix + "minutes", formatValue, varsMap);
                // Seconds - '08'
                formatValue = hms[2];
                maintainDateProperty(prefix + "seconds", formatValue, varsMap);
                // Milliseconds - '324'
                formatValue = hms[3];
                maintainDateProperty(prefix + "milliseconds", formatValue, varsMap);
                // Hours in 24 hours format - '23'
                formatValue = theReferenceDate.toString("HH");
                maintainDateProperty(prefix + "hours24", formatValue, varsMap);
            } else
                setException("Failed to format reference date to four time units!");
        } else {
            setException("Failed to format reference date to its time units!");
        }

        // hours : minutes : seconds (default timestamp)  - '12:34:56'
        formatValue = theReferenceDate.toString("hh:mm:ss");
        maintainDateProperty(prefix + "timeStamp", formatValue, varsMap);

        // Short Year - '14'
        formatValue = theReferenceDate.toString("yy");
        maintainDateProperty(prefix + "shortYear", formatValue, varsMap);

        // Long Year - '2014'
        formatValue = theReferenceDate.toString("yyyy");
        maintainDateProperty(prefix + "longYear", formatValue, varsMap);

        // Short Month - '2'
        formatValue = theReferenceDate.toString("M");
        maintainDateProperty(prefix + "shortMonth", formatValue, varsMap);

        // Padded Month - '02'
        formatValue = theReferenceDate.toString("MM");
        maintainDateProperty(prefix + "paddedMonth", formatValue, varsMap);

        // Short Month Name - 'Feb'
        formatValue = theReferenceDate.toString("MMM");
        maintainDateProperty(prefix + "shortMonthName", formatValue, varsMap);

        // Long Month Name - 'February'
        formatValue = theReferenceDate.toString("MMMM");
        maintainDateProperty(prefix + "longMonthName", formatValue, varsMap);

        // Week in Year - '2014' (the year in which this week falls)
        formatValue = String.valueOf(theReferenceDate.getWeekyear());
        maintainDateProperty(prefix + "weekYear", formatValue, varsMap);

        // Short Day in date stamp - '6'
        formatValue = theReferenceDate.toString("d");
        maintainDateProperty(prefix + "shortDay", formatValue, varsMap);

        // Padded Day in date stamp - possibly with leading 0 - '06'
        formatValue = theReferenceDate.toString("dd");
        maintainDateProperty(prefix + "paddedDay", formatValue, varsMap);

        // Day of Year - '37'
        formatValue = theReferenceDate.toString("D");
        maintainDateProperty(prefix + "yearDay", formatValue, varsMap);

        // Short Day Name - 'Thu'
        formatValue = theReferenceDate.toString("E");
        maintainDateProperty(prefix + "shortDayName", formatValue, varsMap);

        // Long Day Name - 'Thursday'
        DateTime dt = new DateTime(theReferenceDate.toDate());
        DateTime.Property dowDTP = dt.dayOfWeek();
        formatValue = dowDTP.getAsText();
        maintainDateProperty(prefix + "longDayName", formatValue, varsMap);

        // AM/PM - 'AM'
        formatValue = theReferenceDate.toString("a");
        maintainDateProperty(prefix + "ampm", formatValue, varsMap);

        // Era - (BC/AD)
        formatValue = theReferenceDate.toString("G");
        maintainDateProperty(prefix + "era", formatValue, varsMap);

        // Time Zone - 'EST'
        formatValue = theReferenceDate.toString("zzz");
        maintainDateProperty(prefix + "zone", formatValue, varsMap);

        addComment(
                "Date variables replenished for date: " + fullStyleFormatter.format(theReferenceDate.toDate()));
        addComment(theReferenceDate.toString());
        System.out.println(getComments());
    } catch (Exception e) {
        setException(e);
    }
}

From source file:de.jgoldhammer.alfresco.jscript.jmx.JmxDumpUtil.java

/**
 * Show a message stating the JmxDumper has been started, with the current
 * date and time.//from  w  w w.  ja  v a  2s  . c o m
 */
private static void showStartBanner(PrintWriter out) {
    DateFormat df = SimpleDateFormat.getDateTimeInstance(DateFormat.LONG, DateFormat.LONG);
    out.println(JmxDumpUtil.class.getSimpleName() + " started: " + df.format(new Date()));
    out.println();
}

From source file:org.jactr.entry.iterative.IterativeMain.java

/**
 * @param url/* w ww  .j  av a  2  s .  c om*/
 * @param listener
 * @param iterations
 * @throws Exception
 */
public void run(URL url) {
    Collection<IIterativeRunListener> listeners = Collections.EMPTY_LIST;

    try {
        Document environment = loadEnvironment(url);
        int iterations = getIterations(environment);
        listeners = createListeners(environment);

        String id = System.getProperty("iterative-id");
        if (id == null)
            id = "";
        else
            id = "-" + id;

        File rootDir = new File(System.getProperty("user.dir"));
        PrintWriter log = new PrintWriter(new FileWriter("iterative-log" + id + ".xml"));
        log.println("<iterative-run total=\"" + iterations + "\">");

        DateFormat format = DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.LONG);

        boolean shouldExit = false;

        for (IIterativeRunListener listener : listeners)
            try {
                listener.start(iterations);
            } catch (TerminateIterativeRunException tire) {
                shouldExit = true;
            } catch (Exception e) {
                if (LOGGER.isErrorEnabled())
                    LOGGER.error(listener + " threw an exception on start ", e);
            }

        long startTime = System.currentTimeMillis();

        for (int i = 1; i <= iterations; i++) {
            if (shouldExit)
                break;

            /*
             * create a new working directory
             */
            File workingDir = new File(rootDir, "run-" + i);
            workingDir.mkdirs();

            ACTRRuntime.getRuntime().setWorkingDirectory(workingDir);

            log.println(" <run itr=\"" + i + "\" start=\"" + format.format(new Date()) + "\">");

            try {
                /*
                 * let's do it.
                 */
                if (_aggressiveGC)
                    System.gc();

                iteration(i, iterations, environment, url, listeners, log);

                if (_aggressiveGC)
                    System.gc();
            } catch (TerminateIterativeRunException tire) {
                shouldExit = true;
            } catch (Exception e1) {
                log.print(" <exception><![CDATA[");
                e1.printStackTrace(log);
                log.print("]]></exception>");

                for (IIterativeRunListener listener : listeners)
                    try {
                        listener.exceptionThrown(i, null, e1);
                    } catch (TerminateIterativeRunException tire) {
                        shouldExit = true;
                    } catch (Exception e2) {
                        LOGGER.error(listener + " threw an exception on exception notification ", e2);
                    }
            }

            log.println(" </run>");
            log.flush();

            if (workingDir.list().length == 0)
                workingDir.delete();
        }

        String duration = duration(startTime, System.currentTimeMillis());

        if (LOGGER.isDebugEnabled())
            LOGGER.debug("Total running time : " + duration);

        log.println(" <duration value=\"" + duration + "\"/>");
        log.println("</iterative-run>");
        log.close();
    } catch (Exception e) {
        LOGGER.error("Failed to run fully", e);
        for (IIterativeRunListener listener : listeners)
            try {
                // we ignore the return value here since we're exiting anyway
                listener.exceptionThrown(0, null, e);
            } catch (TerminateIterativeRunException tire) {
                // silently swallow since we're already exiting
            } catch (Exception e2) {
                LOGGER.error(listener + " threw an exception during exception notification ", e2);
            }

    } finally {
        for (IIterativeRunListener listener : listeners)
            try {
                listener.stop();
            } catch (Exception e) {
                LOGGER.error(listener + " threw an exception on stop ", e);
            }
    }
}