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.facebook.infrastructure.utils.FBUtilities.java

public static String getTimestamp(long value) {
    Date date = new Date(value);
    DateFormat df = new SimpleDateFormat("MM/dd/yyyy HH:mm:ss");
    return df.format(date);
}

From source file:com.murrayc.murraycgwtpexample.server.ThingServiceImpl.java

private static String getCurrentTime() {
    //TODO: Performance:
    final TimeZone tz = TimeZone.getTimeZone("UTC");
    final DateFormat df = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssz");
    df.setTimeZone(tz);/*from ww w  . ja va 2s.c o m*/
    return df.format(new Date());
}

From source file:com.android.sensorbergVolley.toolbox.HttpHeaderParserTest.java

private static String rfc1123Date(long millis) {
    DateFormat df = new SimpleDateFormat("EEE, dd MMM yyyy HH:mm:ss zzz", Locale.ENGLISH);
    return df.format(new Date(millis));
}

From source file:bullioneconomy.bullionchart.java

public static int[] dateget(String i) throws ParseException {
    String inputDateString = i.trim().replaceAll(" ", "-");
    //System.out.println(inputDateString);
    DateFormat dfTo = new SimpleDateFormat("dd-MMM-yyyy");
    Date inputDate = dfTo.parse(inputDateString);
    DateFormat dayf = new SimpleDateFormat("dd");
    DateFormat monthf = new SimpleDateFormat("MM");
    DateFormat yearf = new SimpleDateFormat("yyyy");
    String oDay = dayf.format(inputDate);
    String oMonth = monthf.format(inputDate);
    String oYear = yearf.format(inputDate);
    int[] k = new int[3];
    k[0] = Integer.parseInt(oDay.toString());
    k[1] = Integer.parseInt(oMonth.toString());
    k[2] = Integer.parseInt(oYear.toString());

    return k;/*w  w  w .  ja v a2  s. com*/
}

From source file:com.microsoft.aad.adal4j.WSTrustRequest.java

private static StringBuilder buildSecurityHeader(StringBuilder securityHeaderBuilder, String username,
        String password, WSTrustVersion version) {

    StringBuilder messageCredentialsBuilder = new StringBuilder(MAX_EXPECTED_MESSAGE_SIZE);
    String guid = UUID.randomUUID().toString();
    username = StringEscapeUtils.escapeXml10(username);
    password = StringEscapeUtils.escapeXml10(password);

    DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'", Locale.US);
    dateFormat.setTimeZone(TimeZone.getTimeZone("UTC"));
    Date date = new Date();
    String currentTimeString = dateFormat.format(date);

    // Expiry is 10 minutes after creation
    int toAdd = 60 * 1000 * 10;
    date = new Date(date.getTime() + toAdd);
    String expiryTimeString = dateFormat.format(date);

    messageCredentialsBuilder.append(String.format("<o:UsernameToken u:Id='uuid-" + "%s'>" + // guid
            "<o:Username>%s</o:Username>" + // username
            "<o:Password>%s</o:Password>" + // password
            "</o:UsernameToken>", guid, username, password));

    securityHeaderBuilder.append(/*  www . j  a v  a2 s  .  c  om*/
            "<o:Security s:mustUnderstand='1' xmlns:o='http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd'>");
    securityHeaderBuilder.append(String.format("<u:Timestamp u:Id='_0'>" + "<u:Created>%s</u:Created>" + // created
            "<u:Expires>%s</u:Expires>" + // Expires
            "</u:Timestamp>", currentTimeString, expiryTimeString));
    securityHeaderBuilder.append(messageCredentialsBuilder.toString());
    securityHeaderBuilder.append("</o:Security>");

    return securityHeaderBuilder;
}

From source file:com.viettel.logistic.common.logs.KPILogger.java

public static void createLogsEndAction(Object paramList, String description, long startTime) {
    DateFormat dateFormat = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss:SSS");
    Date date = new Date();
    Logger businessLog = Logger.getLogger("kpiLog");
    long endTime = System.currentTimeMillis() - startTime;
    businessLog.error("END_ACTION|" + SYSTEM_DEFAULT + "|" + dateFormat.format(date) + "|" + paramList + "|"
            + description + "| Thoi gian : " + endTime);
}

From source file:bizlogic.Command.java

public static int Process(String _command, Connection con, PrintWriter out) throws SQLException {

    try {//from   w  w  w .j  a va 2  s  .  com
        System.out.print("Processing command: ");
        System.out.println(_command);

        String string = _command;
        String[] _array = string.split(",");

        String command = _array[0];

        switch (command) {
        case "addSensor":
            bizlogic.Sensors.add(con, _array[1], _array[2], _array[3], _array[4], _array[5], _array[6]);
            bizlogic.Sensors.list(con);
            break;

        case "delSensor":
            bizlogic.Sensors.del(con, _array[1]);
            bizlogic.Sensors.list(con);
            break;

        case "listSensors":
            bizlogic.Sensors.list(con);
            out.println("sensors.json ok");
            break;

        case "addRecord":
            bizlogic.Records.add(con, _array[1], _array[2], _array[3], _array[4]);
            bizlogic.Records.list(con);
            break;

        case "delRecord":
            bizlogic.Records.del(con, _array[1]);
            bizlogic.Records.list(con);
            break;

        case "startRecords":
            bizlogic.Records.setColumn(con, _array[1], "USERCONF.LOG_LIST", "RUNNING", "true");
            // (conDB, records, column, value)
            //bizlogic.Records.list(con);
            out.println("startRecords " + _array[1]);
            break;

        case "stopRecords":
            bizlogic.Records.setColumn(con, _array[1], "USERCONF.LOG_LIST", "RUNNING", "false");
            // (conDB, records, column, value)
            //bizlogic.Records.list(con);
            out.println("stopRecords " + _array[1]);
            break;

        case "listRecords":
            bizlogic.Records.list(con);
            out.println("listRecords ok");
            break;

        case "writeCSV":
            bizlogic.Records.writeCSV(con, _array[1]);
            out.println("writeCSV " + _array[1] + " Value" + " Time");
            break;

        case "setConf":
            String[] confString = new String[] { "date", "+%D", "--set", _array[3] + " " + _array[2] };
            System.out.println("confString=" + Arrays.toString(confString));
            Process p = java.lang.Runtime.getRuntime().exec(confString);
            int setConf_status = p.waitFor();
            System.out.println("confStatus = " + Integer.toString(setConf_status));
            if (setConf_status != -1) {
                out.println("setConf " + "ok");
            } else {
                out.println("ERROR Date not set");
            }
            break;

        case "serverTime":
            DateFormat sdf = new SimpleDateFormat("dd.MM.yyyy HH:mm:ss");
            Date date = new Date(System.currentTimeMillis());
            out.println("Server time: " + sdf.format(date));
            break;

        case "changeIP":

            if (bizlogic.modSettings.validateIP(_array[1])) {
                System.out.println("changeIP to " + _array[1]);
                bizlogic.modSettings.resetIP();
                if (!_array[1].equals("0.0.0.0")) {
                    bizlogic.modSettings.setIP(_array[1]);
                }
                out.println("Server rebooting to set the IP");
                out.close();
                con.close();
                java.lang.Runtime.getRuntime().exec("sudo reboot");
            } else {
                out.println("ERROR: Bad IP address." + " Enter a valid IPv4 addess");
                System.out.println("Bad IP: " + _array[1]);
                java.lang.Runtime.getRuntime().exec(
                        "pid2=`ps aux | " + "grep \"[d]l_hwlogic\" | awk '{print $2}'`\n" + "kill -9 $pid2");
            }
            break;

        default:
            break;
        }
        return 1;
    } catch (IOException | ParseException | InterruptedException ex) {
        Logger.getLogger(Command.class.getName()).log(Level.WARNING, null, ex);
        return -1;
    }
}

From source file:com.adobe.acs.commons.version.impl.EvolutionConfig.java

public static String printObject(Object obj) {
    if (obj == null) {
        return "";
    }/*from ww  w  .j ava 2s  . co m*/
    if (obj instanceof String) {
        return (String) obj;
    } else if (obj instanceof String[]) {
        String[] values = (String[]) obj;
        StringBuilder result = new StringBuilder();
        result.append("[");
        for (int i = 0; i < values.length; i++) {
            result.append(values[i]);
            if (i != (values.length - 1)) {
                result.append(", ");
            }
        }
        result.append("]");
        return result.toString();
    } else if (obj instanceof Calendar) {
        Calendar value = (Calendar) obj;
        DateFormat dateFormat = DateFormat.getDateTimeInstance();
        dateFormat.setTimeZone(TimeZone.getTimeZone("GMT"));
        return dateFormat.format(value.getTime());
    } else {
        return obj.toString();
    }
}

From source file:com.consol.citrus.samples.flightbooking.entity.converter.FlightConverter.java

/**
 * Get entity form model.//from  www.  j a v a2 s .c o  m
 * @param model
 * @return
 */
public static FlightEntity from(Flight model) {
    DateFormat dateFormat = new SimpleDateFormat("yyyy-dd-MM'T'HH:mm:ss");

    FlightEntity entity = new FlightEntity();

    entity.setAirline(model.getAirline());
    entity.setFlightId(model.getFlightId());
    entity.setFromAirport(model.getFromAirport());
    entity.setScheduledArrival(dateFormat.format(model.getScheduledArrival().getTime()));
    entity.setToAirport(model.getToAirport());
    entity.setScheduledDeparture(dateFormat.format(model.getScheduledDeparture().getTime()));

    return entity;
}

From source file:Main.java

public static void previousDateString(String dateString) throws ParseException {
    DateFormat inputDateFormat = new SimpleDateFormat("dd-MM-yyyy");
    DateFormat outputDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm");

    Calendar now = Calendar.getInstance();
    Calendar calendar = Calendar.getInstance();
    Date myDate = inputDateFormat.parse(dateString);
    calendar.setTime(myDate);/* w  w w  . j  a  va  2  s.  co m*/
    calendar.set(Calendar.HOUR_OF_DAY, now.get(Calendar.HOUR_OF_DAY));
    calendar.set(Calendar.MINUTE, now.get(Calendar.MINUTE));

    String output = outputDateFormat.format(calendar.getTime());
    System.out.println(output);
}