Example usage for java.text DateFormat getDateTimeInstance

List of usage examples for java.text DateFormat getDateTimeInstance

Introduction

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

Prototype

public static final DateFormat getDateTimeInstance(int dateStyle, int timeStyle, Locale aLocale) 

Source Link

Document

Gets the date/time formatter with the given formatting styles for the given locale.

Usage

From source file:org.web4thejob.web.panel.DefaultSessionInfoPanel.java

private void prepareContent() {
    grid.getRows().getChildren().clear();

    Row row = new Row();
    row.setParent(grid.getRows());//from   w w w  .j a v a 2s. com
    Label label = new Label(L10N_LABEL_USER_LOCALE.toString());
    label.setParent(row);
    label = new Label(CoreUtil.getUserLocale().toString());
    label.setParent(row);

    if (ContextUtil.getSessionContext().getSecurityContext().isAdministrator()) {
        row = new Row();
        row.setParent(grid.getRows());
        label = new Label(L10N_LABEL_SERVER_LOCALE.toString());
        label.setParent(row);
        label = new Label(Locale.getDefault().toString());
        label.setParent(row);

        row = new Row();
        row.setParent(grid.getRows());
        label = new Label(L10N_LABEL_SERVER_CHARSET.toString());
        label.setParent(row);
        label = new Label(Charset.defaultCharset().toString());
        label.setParent(row);
    }

    row = new Row();
    row.setParent(grid.getRows());
    label = new Label(L10N_LABEL_REMOTE_ADDRESS.toString());
    label.setParent(row);
    label = new Label(Executions.getCurrent().getServerName() + ":" + Executions.getCurrent().getServerPort());
    label.setParent(row);

    row = new Row();
    row.setParent(grid.getRows());
    label = new Label(L10N_LABEL_LOCAL_ADDRESS.toString());
    label.setParent(row);
    label = new Label(Executions.getCurrent().getLocalAddr() + ":" + Executions.getCurrent().getLocalPort());
    label.setParent(row);

    row = new Row();
    row.setParent(grid.getRows());
    label = new Label(L10N_LABEL_CLIENT_TYPE.toString());
    label.setParent(row);
    label = new Label(Executions.getCurrent().getUserAgent());
    label.setParent(row);

    row = new Row();
    row.setParent(grid.getRows());
    label = new Label(L10N_LABEL_DEVICE_TYPE.toString());
    label.setParent(row);
    label = new Label(Executions.getCurrent().getSession().getDeviceType());
    label.setParent(row);

    final ClientInfoEvent info = ContextUtil.getSessionContext().getAttribute(ATTRIB_CLIENT_INFO);
    if (info != null) {
        row = new Row();
        row.setParent(grid.getRows());
        label = new Label(L10N_LABEL_SCREEN_RESOLUTION.toString());
        label.setParent(row);
        label = new Label(info.getScreenWidth() + "x" + info.getScreenHeight() + " px");
        label.setParent(row);

        row = new Row();
        row.setParent(grid.getRows());
        label = new Label(L10N_LABEL_COLOR_DEPTH.toString());
        label.setParent(row);
        label = new Label(String.valueOf(info.getColorDepth()) + "-bit");
        label.setParent(row);
    }

    DateFormat formatter = DateFormat.getDateTimeInstance(DateFormat.FULL, DateFormat.FULL,
            CoreUtil.getUserLocale());

    if (Executions.getCurrent().getSession().getNativeSession() instanceof HttpSession) {
        HttpSession session = (HttpSession) Executions.getCurrent().getSession().getNativeSession();

        row = new Row();
        row.setParent(grid.getRows());
        label = new Label(L10N_LABEL_SESSION_TIMEOUT.toString());
        label.setParent(row);
        label = new Label(String.valueOf(session.getMaxInactiveInterval() / 60) + "'");
        label.setParent(row);

        row = new Row();
        row.setParent(grid.getRows());
        label = new Label(L10N_LABEL_SESSION_CREATE_TIME.toString());
        label.setParent(row);
        label = new Label(formatter.format(new Date(session.getCreationTime())));
        label.setParent(row);

        row = new Row();
        row.setParent(grid.getRows());
        label = new Label(L10N_LABEL_SESSION_ACCESSED_TIME.toString());
        label.setParent(row);
        label = new Label(formatter.format(new Date(session.getLastAccessedTime())));
        label.setParent(row);
    }

}

From source file:org.hoteia.qalingo.core.web.util.impl.RequestUtilImpl.java

/**
*
*//*from w ww  .  j av a2s .  c  om*/
public DateFormat getFormatDate(final RequestData requestData, final int dateStyle, final int timeStyle)
        throws Exception {
    final Locale locale = requestData.getLocale();
    DateFormat formatter = DateFormat.getDateTimeInstance(dateStyle, timeStyle, locale);
    return formatter;
}

From source file:org.jivesoftware.util.JiveGlobals.java

/**
 * Formats a Date object to return a date and time using the global locale.
 *
 * @param date the Date to format./*w w  w .j  a v a  2 s.  c  o m*/
 * @return a String representing the date and time.
 */
public static String formatDateTime(Date date) {
    if (dateTimeFormat == null) {
        if (properties != null) {
            dateTimeFormat = DateFormat.getDateTimeInstance(DateFormat.MEDIUM, DateFormat.MEDIUM, getLocale());
            dateTimeFormat.setTimeZone(getTimeZone());
        } else {
            DateFormat instance = DateFormat.getDateTimeInstance(DateFormat.MEDIUM, DateFormat.MEDIUM,
                    getLocale());
            instance.setTimeZone(getTimeZone());
            return instance.format(date);
        }
    }
    return dateTimeFormat.format(date);
}

From source file:org.pentaho.reporting.engine.classic.core.modules.gui.base.parameters.DatePickerParameterComponent.java

private DateFormat createDateFormat(final String parameterFormatString, final Locale locale,
        final TimeZone timeZone) {
    if (parameterFormatString != null) {
        try {//from  w w  w . j  ava 2s  . c  om
            final SimpleDateFormat dateFormat = new SimpleDateFormat(parameterFormatString, locale);
            dateFormat.setTimeZone(timeZone);
            dateFormat.setLenient(false);
            return dateFormat;
        } catch (Exception e) {
            // boo! Not a valid pattern ...
            // its not a show-stopper either, as the pattern is a mere hint, not a mandatory thing
            logger.warn("Parameter format-string for date-parameter was not a valid date-format-string", e); // NON-NLS
        }
    }

    return DateFormat.getDateTimeInstance(DateFormat.LONG, DateFormat.LONG, locale);
}

From source file:org.lbogdanov.poker.web.page.SessionPage.java

private String formatDate(Date created) {
    final long MILLIS_PER_WEEK = TimeUnit.DAYS.toMillis(7);
    Locale locale = getLocale();//from   w  ww  . ja  v  a 2 s. co m
    PrettyTime prettyTime = new PrettyTime(locale);
    Duration largest = Iterables.getFirst(prettyTime.calculatePreciseDuration(created), null);
    if (largest != null && largest.getUnit().getMillisPerUnit() < MILLIS_PER_WEEK) {
        return prettyTime.format(largest);
    } else { // fallback to an absolute date string when difference is more than a week
        return DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.SHORT, locale).format(created);
    }
}

From source file:org.parakoopa.udphp.mediator.Mediator.java

/**
 * Logs to the console (if quiet was not set) and to the logfile if specified
 * The logfile will also get timestamps for each event.
 * @param str String to log/*from  www  .  j  a  va 2 s  .c om*/
 * @param verbose boolean Should this be logged only with --verbose?
 */
public static void log(String str, boolean verbose) {
    //Don't print verbose lines if not requested
    if (verbose && !Mediator.verbose)
        return;
    /* CONSOLE OUTPUT */
    if (!Mediator.quiet) {
        System.out.println(str);
    }
    /* FILE LOG */
    if (Mediator.log != null) {
        DateFormat date = DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.SHORT,
                Locale.getDefault());
        try (PrintWriter out = new PrintWriter(new BufferedWriter(new FileWriter(Mediator.log, true)))) {
            out.println(date.format(new Date()) + " : " + str);
        } catch (IOException ex) {
            Logger.getLogger(Mediator.class.getName()).log(Level.SEVERE, null, ex);
        }
    }
}

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

/**
 * //ww w  .jav  a2 s .c o  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:at.alladin.rmbt.controlServer.HistoryResource.java

@Post("json")
public String request(final String entity) {
    long startTime = System.currentTimeMillis();
    addAllowOrigin();/* w ww  .  jav a  2 s.c  om*/

    JSONObject request = null;

    final ErrorList errorList = new ErrorList();
    final JSONObject answer = new JSONObject();
    String answerString;

    final String clientIpRaw = getIP();
    System.out.println(MessageFormat.format(labels.getString("NEW_HISTORY"), clientIpRaw));

    if (entity != null && !entity.isEmpty())
        // try parse the string to a JSON object
        try {
            request = new JSONObject(entity);

            String lang = request.optString("language");

            // Load Language Files for Client

            final List<String> langs = Arrays
                    .asList(settings.getString("RMBT_SUPPORTED_LANGUAGES").split(",\\s*"));

            if (langs.contains(lang)) {
                errorList.setLanguage(lang);
                labels = ResourceManager.getSysMsgBundle(new Locale(lang));
            } else
                lang = settings.getString("RMBT_DEFAULT_LANGUAGE");

            //                System.out.println(request.toString(4));

            if (conn != null) {
                final Client client = new Client(conn);

                if (request.optString("uuid").length() > 0
                        && client.getClientByUuid(UUID.fromString(request.getString("uuid"))) > 0) {

                    final Locale locale = new Locale(lang);
                    final Format format = new SignificantFormat(2, locale);

                    String limitRequest = "";
                    if (request.optInt("result_limit", 0) != 0) {
                        final int limit = request.getInt("result_limit");

                        //get offset string if there is one
                        String offsetString = "";
                        if ((request.optInt("result_offset", 0) != 0)
                                && (request.getInt("result_offset") >= 0)) {
                            offsetString = " OFFSET " + request.getInt("result_offset");
                        }

                        limitRequest = " LIMIT " + limit + offsetString;
                    }

                    final ArrayList<String> deviceValues = new ArrayList<>();
                    String deviceRequest = "";
                    if (request.optJSONArray("devices") != null) {
                        final JSONArray devices = request.getJSONArray("devices");

                        boolean checkUnknown = false;
                        final StringBuffer sb = new StringBuffer();
                        for (int i = 0; i < devices.length(); i++) {
                            final String device = devices.getString(i);

                            if (device.equals("Unknown Device"))
                                checkUnknown = true;
                            else {
                                if (sb.length() > 0)
                                    sb.append(',');
                                deviceValues.add(device);
                                sb.append('?');
                            }
                        }

                        if (sb.length() > 0)
                            deviceRequest = " AND (COALESCE(adm.fullname, t.model) IN (" + sb.toString() + ")"
                                    + (checkUnknown ? " OR model IS NULL OR model = ''" : "") + ")";
                        //                            System.out.println(deviceRequest);

                    }

                    final ArrayList<String> filterValues = new ArrayList<>();
                    String networksRequest = "";

                    if (request.optJSONArray("networks") != null) {
                        final JSONArray tmpArray = request.getJSONArray("networks");
                        final StringBuilder tmpString = new StringBuilder();

                        if (tmpArray.length() >= 1) {
                            tmpString.append("AND nt.group_name IN (");
                            boolean first = true;
                            for (int i = 0; i < tmpArray.length(); i++) {
                                if (first)
                                    first = false;
                                else
                                    tmpString.append(',');
                                tmpString.append('?');
                                filterValues.add(tmpArray.getString(i));
                            }
                            tmpString.append(')');
                        }
                        networksRequest = tmpString.toString();
                    }

                    final JSONArray historyList = new JSONArray();

                    final PreparedStatement st;

                    try {
                        if (client.getSync_group_id() == 0) {
                            //use faster request ignoring sync-group as user is not synced (id=0)
                            st = conn.prepareStatement(String.format(

                                    "SELECT DISTINCT"
                                            + " t.uuid, time, timezone, speed_upload, speed_download, ping_median, network_type, nt.group_name network_type_group_name,"
                                            + " COALESCE(adm.fullname, t.model) model" + " FROM test t"
                                            + " LEFT JOIN device_map adm ON adm.codename=t.model"
                                            + " LEFT JOIN network_type nt ON t.network_type=nt.uid"
                                            + " WHERE t.deleted = false AND t.implausible = false AND t.status = 'FINISHED'"
                                            + " AND client_id = ?" + " %s %s" + " ORDER BY time DESC" + " %s",
                                    deviceRequest, networksRequest, limitRequest));
                        } else { //use slower request including sync-group if client is synced
                            st = conn.prepareStatement(String.format("SELECT DISTINCT"
                                    + " t.uuid, time, timezone, speed_upload, speed_download, ping_median, network_type, nt.group_name network_type_group_name,"
                                    + " COALESCE(adm.fullname, t.model) model" + " FROM test t"
                                    + " LEFT JOIN device_map adm ON adm.codename=t.model"
                                    + " LEFT JOIN network_type nt ON t.network_type=nt.uid"
                                    + " WHERE t.deleted = false AND t.implausible = false AND t.status = 'FINISHED'"
                                    + " AND (t.client_id IN (SELECT ? UNION SELECT uid FROM client WHERE sync_group_id = ? ))"
                                    + " %s %s" + " ORDER BY time DESC" + " %s", deviceRequest, networksRequest,
                                    limitRequest));

                        }

                        int i = 1;
                        st.setLong(i++, client.getUid());
                        if (client.getSync_group_id() != 0)
                            st.setInt(i++, client.getSync_group_id());

                        for (final String value : deviceValues)
                            st.setString(i++, value);

                        for (final String filterValue : filterValues)
                            st.setString(i++, filterValue);

                        //System.out.println(st.toString());

                        final ResultSet rs = st.executeQuery();

                        while (rs.next()) {
                            final JSONObject jsonItem = new JSONObject();

                            jsonItem.put("test_uuid", rs.getString("uuid"));

                            final Date date = rs.getTimestamp("time");
                            final long time = date.getTime();
                            final String tzString = rs.getString("timezone");
                            final TimeZone tz = TimeZone.getTimeZone(tzString);
                            jsonItem.put("time", time);
                            jsonItem.put("timezone", tzString);
                            final DateFormat dateFormat = DateFormat.getDateTimeInstance(DateFormat.MEDIUM,
                                    DateFormat.MEDIUM, locale);
                            dateFormat.setTimeZone(tz);
                            jsonItem.put("time_string", dateFormat.format(date));

                            jsonItem.put("speed_upload", format.format(rs.getInt("speed_upload") / 1000d));
                            jsonItem.put("speed_download", format.format(rs.getInt("speed_download") / 1000d));

                            final long ping = rs.getLong("ping_median");
                            jsonItem.put("ping", format.format(ping / 1000000d));
                            // backwards compatibility for old clients
                            jsonItem.put("ping_shortest", format.format(ping / 1000000d));
                            jsonItem.put("model", rs.getString("model"));
                            jsonItem.put("network_type", rs.getString("network_type_group_name"));

                            //for appscape-iPhone-Version: also add classification to the response
                            jsonItem.put("speed_upload_classification", Classification
                                    .classify(classification.THRESHOLD_UPLOAD, rs.getInt("speed_upload")));
                            jsonItem.put("speed_download_classification", Classification
                                    .classify(classification.THRESHOLD_DOWNLOAD, rs.getInt("speed_download")));
                            jsonItem.put("ping_classification", Classification
                                    .classify(classification.THRESHOLD_PING, rs.getLong("ping_median")));
                            // backwards compatibility for old clients
                            jsonItem.put("ping_shortest_classification", Classification
                                    .classify(classification.THRESHOLD_PING, rs.getLong("ping_median")));

                            historyList.put(jsonItem);
                        }

                        if (historyList.length() == 0)
                            errorList.addError("ERROR_DB_GET_HISTORY");
                        // errorList.addError(MessageFormat.format(labels.getString("ERROR_DB_GET_CLIENT"),
                        // new Object[] {uuid}));

                        rs.close();
                        st.close();
                    } catch (final SQLException e) {
                        e.printStackTrace();
                        errorList.addError("ERROR_DB_GET_HISTORY_SQL");
                        // errorList.addError("ERROR_DB_GET_CLIENT_SQL");
                    }

                    answer.put("history", historyList);
                } else
                    errorList.addError("ERROR_REQUEST_NO_UUID");

            } else
                errorList.addError("ERROR_DB_CONNECTION");

        } catch (final JSONException e) {
            errorList.addError("ERROR_REQUEST_JSON");
            System.out.println("Error parsing JSDON Data " + e.toString());
        } catch (final IllegalArgumentException e) {
            errorList.addError("ERROR_REQUEST_NO_UUID");
        }
    else
        errorList.addErrorString("Expected request is missing.");

    try {
        answer.putOpt("error", errorList.getList());
    } catch (final JSONException e) {
        System.out.println("Error saving ErrorList: " + e.toString());
    }

    answerString = answer.toString();

    long elapsedTime = System.currentTimeMillis() - startTime;
    System.out.println(MessageFormat.format(labels.getString("NEW_HISTORY_SUCCESS"), clientIpRaw,
            Long.toString(elapsedTime)));

    return answerString;
}

From source file:Dates.java

public static String dateTimeFormatForJSCalendar(Locale locale) {
    DateFormat df = DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.SHORT, locale);
    String datetime = df.format(create(1, 2, 1971, 15, 59, 0)); // d, m, y, hr, min, sec 
    boolean always4InYear = "es".equals(locale.getLanguage()) || "pl".equals(locale.getLanguage());
    String result = datetime./*from w  ww.ja  v a  2  s. c  o m*/

    // time part
            replaceAll("15", "%H"). // 24hr format 
            replaceAll("03", "%I"). // 12hr format - double digit 
            replaceAll("3", "%l"). // 12hr format - single digit
            replaceAll("59", "%M"). // minute
            replaceAll("PM", "%p"). // AM/PM - uppercase
            replaceAll("pm", "%P"). // am/pm - lowercase

            // date part
            replaceAll("01", "%d"). // day - double digit
            replaceAll("02", "%m"). // month - double digit
            replaceAll("1971", "%Y"). // year - 4 digit
            replaceAll("71", always4InYear ? "%Y" : "%y"). // year - 2 digit     
            replaceAll("1", "%e"). // day - single digit
            replaceAll("2", "%m") // month - ??? seems only double digit is supported by calendar
    ;

    return result;
}

From source file:me.ryanhamshire.PopulationDensity.DataStore.java

public void savePlayerData(OfflinePlayer player, PlayerData data) {
    //save that data in memory
    this.playerNameToPlayerDataMap.put(player.getUniqueId().toString(), data);

    BufferedWriter outStream = null;
    try {//from   w ww  .  j  a  v  a2 s  .  c om
        //open the player's file
        File playerFile = new File(playerDataFolderPath + File.separator + player.getUniqueId().toString());
        playerFile.createNewFile();
        outStream = new BufferedWriter(new FileWriter(playerFile));

        //first line is home region coordinates
        outStream.write(data.homeRegion.toString());
        outStream.newLine();

        //second line is last disconnection date,
        //note use of the ROOT locale to avoid problems related to regional settings on the server being updated
        DateFormat dateFormat = DateFormat.getDateTimeInstance(DateFormat.FULL, DateFormat.FULL, Locale.ROOT);
        outStream.write(dateFormat.format(data.lastDisconnect));
        outStream.newLine();

        //third line is login priority
        outStream.write(String.valueOf(data.loginPriority));
        outStream.newLine();
    }

    //if any problem, log it
    catch (Exception e) {
        PopulationDensity.AddLogEntry("PopulationDensity: Unexpected exception saving data for player \""
                + player.getName() + "\": " + e.getMessage());
    }

    try {
        //close the file
        if (outStream != null)
            outStream.close();
    } catch (IOException exception) {
    }
}