Example usage for java.text DateFormat format

List of usage examples for java.text DateFormat format

Introduction

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

Prototype

public final String format(Date date) 

Source Link

Document

Formats a Date into a date-time string.

Usage

From source file:com.indoqa.lang.util.TimeUtils.java

public static String formatSolrDate(Date date) {
    DateFormat dateFormat = new SimpleDateFormat(SOLR_DATE_FORMAT);
    dateFormat.setTimeZone(TIME_ZONE);/*from w ww . j av a  2  s . c  o m*/
    return dateFormat.format(date);
}

From source file:com.dhenton9000.selenium.generic.UtilMethods.java

public static String getPreviousDate(int daysAgo) {
    DateFormat newFormat = new SimpleDateFormat("MM/dd/yyyy");
    newFormat.setLenient(true);/* w w w .ja  v a 2  s.  co m*/
    Calendar cal = Calendar.getInstance();
    cal.setTime(new java.util.Date());
    cal.add(Calendar.DATE, -1 * daysAgo);
    return newFormat.format(cal.getTime());
}

From source file:uk.ac.kcl.Transform23.java

public static Writable getIso8601TimeFromMSH(MSH msh) {

    TS ts = msh.getDateTimeOfMessage();/*from   www  .  j a  v a  2  s. c o m*/
    Date date = null;
    try {
        date = ts.getTimeOfAnEvent().getValueAsDate();
    } catch (DataTypeException ex) {
        Logger.getLogger(Transform23.class.getName()).log(Level.SEVERE, null, ex);
        return NullWritable.get();
    }

    DateFormat df = new SimpleDateFormat("yyyy-MM-dd'T'HH:mmZ");
    String returnString = null;
    try {
        returnString = df.format(date);
    } catch (NullPointerException ex) {
        return NullWritable.get();
    }
    System.out.println(returnString);
    return new Text(returnString);
}

From source file:uk.ac.kcl.Transform231.java

public static Writable getIso8601TimeFromMSH(MSH msh) {

    TS ts = msh.getDateTimeOfMessage();/*from w ww. j  ava2  s  . c  om*/
    Date date = null;
    try {
        date = ts.getTimeOfAnEvent().getValueAsDate();
    } catch (DataTypeException ex) {
        Logger.getLogger(Transform231.class.getName()).log(Level.SEVERE, null, ex);
        return NullWritable.get();
    }

    DateFormat df = new SimpleDateFormat("yyyy-MM-dd'T'HH:mmZ");
    String returnString = null;
    try {
        returnString = df.format(date);
    } catch (NullPointerException ex) {
        return NullWritable.get();
    }
    System.out.println(returnString);
    return new Text(returnString);
}

From source file:com.alu.e3.common.tools.WsseTools.java

public static String getCreated(Date when) {
    String date = null;// w  w w  .  java  2 s .  c  o  m
    for (DateFormat format : matchingFormats) {
        synchronized (format) { // some implementations of SimpleDateFormat are not thread-safe
            date = format.format(when);
            return date;
        }
    }
    return date;
}

From source file:elaborate.editor.solr.ElaborateSolrIndexer.java

private static void handleCNWFacets(String facetName, String value, SolrInputDocument doc) {
    if ("metadata_afzender".equals(facetName) || "metadata_ontvanger".equals(facetName)) {
        for (String correspondent : extractCorrespondents(value)) {
            doc.addField("mv_metadata_correspondents", correspondent, 1.0f);
        }//from   w  ww .j av  a2s .c  o  m
    } else if ("metadata_datum".equals(facetName)) {
        if (StringUtils.isNotBlank(value)) {
            Datable datable = new Datable(CNW_UTIL.convertDate(value));
            if (datable.isValid() && !value.startsWith("XXXX")) {
                // ignore dates where year is not known
                DateFormat dateFormat = new SimpleDateFormat("yyyyMMdd");
                doc.addField("metadata_datum_lower", dateFormat.format(datable.getFromDate()), 1.0f);
                doc.addField("metadata_datum_upper", dateFormat.format(datable.getToDate()), 1.0f);
            } else {
                Log.error("invalid datable: {}", value);
            }
        } else {
            Log.error("invalid datum: '{}'", value);
        }
    }
}

From source file:com.ikon.util.FormatUtil.java

/**
 * Format time for human readers//  w ww.jav a2  s  .  c  o m
 */
public static String formatTime(long time) {
    DateFormat df = new SimpleDateFormat("HH:mm:ss.SSS");
    String str = df.format(time);
    return str;
}

From source file:net.gazeplay.commons.utils.games.Utils.java

/**
 * @return current time with respect to the format HH:MM:ss
 *//*from w ww. j a  va2  s  . c om*/
public static String time() {

    DateFormat dateFormat = new SimpleDateFormat("HH:MM:ss");
    Date date = new Date();
    return dateFormat.format(date);
}

From source file:com.plugin.autoflox.invarscope.aji.executiontracer.JSExecutionTracer.java

/**
 * Retrieves the JavaScript instrumentation array from the webbrowser and
 * writes its contents in Daikon format to a file.
 * //from  w  ww  .j  a  v  a 2s.c  o m
 * @param session
 *            The crawling session.
 * @param candidateElements
 *            The candidate clickable elements.
 */
public static void generateTrace(String state, String outputFolder) {

    currentState = state;

    String filename = outputFolder + EXECUTIONTRACEDIRECTORY + "jsexecutiontrace-";
    filename += state;

    DateFormat dateFormat = new SimpleDateFormat("yyyyMMddHHmmss");
    Date date = new Date();
    filename += dateFormat.format(date) + ".dtrace";

    traceVector.addElement(filename);
    System.out.println("traceVector size: " + traceVector.size());

    try {

        /*
         * FIXME: Frank, hack to send last buffer items and wait for them to
         * arrive
         */
        //session.getBrowser().executeJavaScript("sendReally();");

        Trace trace = Trace.parse(points);

        PrintWriter file = new PrintWriter(filename);
        file.write(trace.getDeclaration());
        file.write('\n');
        file.write(trace.getData(points));
        file.close();

        System.out.println("Points before cleaned: \n" + points.toString());
        // Justin: We dont need empty points array now since we want to trace multiple errors
        //points = new JSONArray();

    } catch (Exception e) {
        e.printStackTrace();
    }

    /* FROLIN - TRY TO RETRIEVE DOM */
    /*
    try {
       NodeList nlist = session.getCurrentState().getDocument()
       .getElementsByTagName("*");
       System.out.println("State IDs");
       for (int i = 0; i < nlist.getLength(); i++) {
    Element e = (Element) nlist.item(i);
    if (e.hasAttribute("id")) {
       System.out.println(e.getAttribute("id"));
    }
       }
       System.out.println("\n");
    } catch (Exception ee) {
       System.out.println("Error: Exception when retrieving document");
       System.exit(-1);
    }
    */
    /* END TRY TO RETRIEVE DOM */
}

From source file:DateUtil.java

/**
 * Formats given date according to specified locale and date style
 *
 * @param date      Date to convert/*w w w. j av a 2  s  . com*/
 * @param locale    Locale to use for formatting date
 * @param dateStyle Date style
 * @return String representation of date according to given locale and date style
 * @see java.text.DateFormat
 */
public static String formatDate(Date date, Locale locale, int dateStyle) {
    DateFormat formatter = DateFormat.getDateInstance(dateStyle, locale);
    return formatter.format(date);
}