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.apache.maven.plugin.doap.DoapUtil.java

/**
 * Write comments in the DOAP file header
 *
 * @param writer not null//from   w ww  . j a v  a 2 s . com
 */
public static void writeHeader(XMLWriter writer) {
    XmlWriterUtil.writeLineBreak(writer);

    XmlWriterUtil.writeCommentLineBreak(writer);
    XmlWriterUtil.writeComment(writer, StringUtils.repeat("=", REPEAT_EQUALS) + " - DO NOT EDIT THIS FILE! - "
            + StringUtils.repeat("=", REPEAT_EQUALS));
    XmlWriterUtil.writeCommentLineBreak(writer);
    XmlWriterUtil.writeComment(writer, " ");
    XmlWriterUtil.writeComment(writer, "Any modifications will be overwritten.");
    XmlWriterUtil.writeComment(writer, " ");
    DateFormat dateFormat = DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.SHORT, Locale.US);
    XmlWriterUtil.writeComment(writer, "Generated by Maven Doap Plugin " + getPluginVersion() + " on "
            + dateFormat.format(new Date(System.currentTimeMillis())));
    XmlWriterUtil.writeComment(writer, "See: http://maven.apache.org/plugins/maven-doap-plugin/");
    XmlWriterUtil.writeComment(writer, " ");
    XmlWriterUtil.writeCommentLineBreak(writer);

    XmlWriterUtil.writeLineBreak(writer);
}

From source file:org.nuxeo.ecm.platform.ui.web.component.seam.UICellExcel.java

/**
 * Converts string value as returned by widget to the target type for an accurate cell format in the XLS/CSV export.
 * <ul>/*from   w  ww . j av a2  s.  c o m*/
 * <li>If force type is set to "number", convert value to a double (null if empty).</li>
 * <li>If force type is set to "bool", convert value to a boolean (null if empty).</li>
 * <li>If force type is set to "date", convert value to a date using most frequent date parsers using the short,
 * medium, long and full formats and current locale, trying first with time information and after with only date
 * information. Returns null if date is empty or could not be parsed.</li>
 * </ul>
 *
 * @since 5.6
 */
protected Object convertStringToTargetType(String value, String forceType) {
    if (CellType.number.name().equals(forceType)) {
        if (StringUtils.isBlank(value)) {
            return null;
        }
        return Double.valueOf(value);
    } else if (CellType.date.name().equals(forceType)) {
        if (StringUtils.isBlank(value)) {
            return null;
        }
        Locale locale = FacesContext.getCurrentInstance().getViewRoot().getLocale();
        int[] formats = { DateFormat.SHORT, DateFormat.MEDIUM, DateFormat.LONG, DateFormat.FULL };
        for (int format : formats) {
            try {
                return DateFormat.getDateTimeInstance(format, format, locale).parse(value);
            } catch (ParseException e) {
                // ignore
            }
            try {
                return DateFormat.getDateInstance(format, locale).parse(value);
            } catch (ParseException e) {
                // ignore
            }
        }
        log.warn("Could not convert value to a date instance: " + value);
        return null;
    } else if (CellType.bool.name().equals(forceType)) {
        if (StringUtils.isBlank(value)) {
            return null;
        }
        return Boolean.valueOf(value);
    }
    return value;
}

From source file:com.egoists.coco_nut.android.util.EtcUtils.java

public static String getSimpleDateString(long millis) {
    String time = null;//  ww  w. j a v a2 s.  c  om

    if (Locale.getDefault().equals(Locale.KOREA) || Locale.getDefault().equals(Locale.KOREAN)) {
        SimpleDateFormat formatter = new SimpleDateFormat("yyyy M d? a h mm",
                Locale.getDefault());
        time = formatter.format(new Date(millis));
    } else {
        time = DateFormat.getDateTimeInstance(DateFormat.MEDIUM, DateFormat.SHORT, Locale.getDefault())
                .format(new Date(millis));
    }

    return time;
}

From source file:org.openmrs.web.taglib.FormatDateTag.java

public int doStartTag() {
    RequestContext requestContext = (RequestContext) this.pageContext
            .getAttribute(RequestContextAwareTag.REQUEST_CONTEXT_PAGE_ATTRIBUTE);

    if (date == null && getPath() != null) {
        try {/* w  w  w.ja  v a 2 s  .  c o m*/
            // get the "path" object from the pageContext
            String resolvedPath = getPath();
            String nestedPath = (String) pageContext.getAttribute(NestedPathTag.NESTED_PATH_VARIABLE_NAME,
                    PageContext.REQUEST_SCOPE);
            if (nestedPath != null) {
                resolvedPath = nestedPath + resolvedPath;
            }

            BindStatus status = new BindStatus(requestContext, resolvedPath, false);
            log.debug("status: " + status);

            if (status.getValue() != null) {
                log.debug("status.value: " + status.getValue());
                if (status.getValue().getClass() == Date.class) {
                    // if no editor was registered all will go well here
                    date = (Date) status.getValue();
                } else {
                    // if a "Date" property editor was registerd for the form, the status.getValue()
                    // object will be a java.lang.String.  This is useless.  Try getting the original
                    // value from the troublesome editor
                    log.debug("status.valueType: " + status.getValueType());
                    Timestamp timestamp = (Timestamp) status.getEditor().getValue();
                    date = new Date(timestamp.getTime());
                }
            }
        } catch (Exception e) {
            log.warn("Unable to get a date object from path: " + getPath(), e);
            return SKIP_BODY;
        }
    }

    if (!dateWasSet && date == null) {
        log.warn("Both 'date' and 'path' cannot be null.  Page: " + pageContext.getPage() + " localname:"
                + pageContext.getRequest().getLocalName() + " rd:"
                + pageContext.getRequest().getRequestDispatcher(""));
        return SKIP_BODY;
    }

    if (type == null) {
        type = "";
    }

    DateFormat dateFormat = null;

    if (format != null && format.length() > 0) {
        dateFormat = new SimpleDateFormat(format, Context.getLocale());
    } else if (type.equals("xml")) {
        dateFormat = new SimpleDateFormat("dd-MMM-yyyy", Context.getLocale());
    } else {
        log.debug("context locale: " + Context.getLocale());

        if (type.equals("long")) {
            dateFormat = DateFormat.getDateTimeInstance(DateFormat.LONG, DateFormat.LONG, Context.getLocale());
        } else if (type.equals("medium")) {
            dateFormat = DateFormat.getDateInstance(DateFormat.MEDIUM, Context.getLocale());
        } else {
            dateFormat = Context.getDateFormat();
        }
    }

    if (dateFormat == null) {
        dateFormat = new SimpleDateFormat("MM-dd-yyyy");
    }

    String datestr = "";

    try {
        if (date != null) {
            if (type.equals("milliseconds")) {
                datestr = "" + date.getTime();
            } else {
                if (showTodayOrYesterday && (DateUtils.isSameDay(Calendar.getInstance().getTime(), date)
                        || OpenmrsUtil.isYesterday(date))) {
                    //print only time of day but maintaining the format(24 Vs 12) if any was specified
                    String timeFormatString = (format != null && !format.contains("a")) ? "HH:mm" : "h:mm a";
                    dateFormat = new SimpleDateFormat(timeFormatString);
                    if (DateUtils.isSameDay(Calendar.getInstance().getTime(), date)) {
                        datestr = Context.getMessageSourceService().getMessage("general.today") + " "
                                + dateFormat.format(date);
                    } else {
                        datestr = Context.getMessageSourceService().getMessage("general.yesterday") + " "
                                + dateFormat.format(date);
                    }
                } else {
                    datestr = dateFormat.format(date);
                }
            }
        }
    } catch (IllegalArgumentException e) {
        //format or date is invalid
        log.error("date: " + date);
        log.error("format: " + format);
        log.error(e);
        datestr = date.toString();
    }

    try {
        pageContext.getOut().write(datestr);
    } catch (IOException e) {
        log.error(e);
    }

    // reset the objects to null because taglibs are reused
    release();

    return SKIP_BODY;
}

From source file:at.alladin.rmbt.controlServer.TestResultResource.java

@Post("json")
public String request(final String entity) {
    long startTime = System.currentTimeMillis();
    addAllowOrigin();//  www.j  a  va 2 s .c o  m

    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_TESTRESULT"), 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);
                final Test test = new Test(conn);

                final String testUuid = request.optString("test_uuid");
                if (testUuid != null && test.getTestByUuid(UUID.fromString(testUuid)) > 0
                        && client.getClientByUid(test.getField("client_id").intValue())
                        && "FINISHED".equals(test.getField("status").toString())) {

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

                    final JSONArray resultList = new JSONArray();

                    final JSONObject jsonItem = new JSONObject();

                    JSONArray jsonItemList = new JSONArray();

                    // RMBTClient Info
                    //also send open-uuid (starts with 'P')
                    final String openUUID = "P" + ((UUIDField) test.getField("open_uuid")).toString();
                    jsonItem.put("open_uuid", openUUID);

                    //and open test-uuid (starts with 'O')
                    final String openTestUUID = "O" + ((UUIDField) test.getField("open_test_uuid")).toString();
                    jsonItem.put("open_test_uuid", openTestUUID);

                    final Date date = ((TimestampField) test.getField("time")).getDate();
                    final long time = date.getTime();
                    final String tzString = test.getField("timezone").toString();
                    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);
                    final String timeString = dateFormat.format(date);
                    jsonItem.put("time_string", timeString);

                    final Field fieldDown = test.getField("speed_download");
                    JSONObject singleItem = new JSONObject();
                    singleItem.put("title", labels.getString("RESULT_DOWNLOAD"));
                    final String downloadString = String.format("%s %s",
                            format.format(fieldDown.doubleValue() / 1000d),
                            labels.getString("RESULT_DOWNLOAD_UNIT"));
                    singleItem.put("value", downloadString);
                    singleItem.put("classification",
                            Classification.classify(classification.THRESHOLD_DOWNLOAD, fieldDown.intValue()));

                    jsonItemList.put(singleItem);

                    final Field fieldUp = test.getField("speed_upload");
                    singleItem = new JSONObject();
                    singleItem.put("title", labels.getString("RESULT_UPLOAD"));
                    final String uploadString = String.format("%s %s",
                            format.format(fieldUp.doubleValue() / 1000d),
                            labels.getString("RESULT_UPLOAD_UNIT"));
                    singleItem.put("value", uploadString);
                    singleItem.put("classification",
                            Classification.classify(classification.THRESHOLD_UPLOAD, fieldUp.intValue()));

                    jsonItemList.put(singleItem);

                    final Field fieldPing = test.getField("ping_median");
                    String pingString = "";
                    if (!fieldPing.isNull()) {
                        final double pingValue = fieldPing.doubleValue() / 1000000d;
                        singleItem = new JSONObject();
                        singleItem.put("title", labels.getString("RESULT_PING"));
                        pingString = String.format("%s %s", format.format(pingValue),
                                labels.getString("RESULT_PING_UNIT"));
                        singleItem.put("value", pingString);
                        singleItem.put("classification",
                                Classification.classify(classification.THRESHOLD_PING, fieldPing.longValue()));

                        jsonItemList.put(singleItem);
                    }

                    final int networkType = test.getField("network_type").intValue();

                    final Field signalField = test.getField("signal_strength"); // signal strength as RSSI (GSM, UMTS, Wifi, sometimes LTE)
                    final Field lteRsrpField = test.getField("lte_rsrp"); // signal strength as RSRP, used in LTE
                    String signalString = null;
                    if (!signalField.isNull() || !lteRsrpField.isNull()) {
                        if (lteRsrpField.isNull()) { // only RSSI value, output RSSI to JSON  
                            final int signalValue = signalField.intValue();
                            final int[] threshold = networkType == 99 || networkType == 0
                                    ? classification.THRESHOLD_SIGNAL_WIFI
                                    : classification.THRESHOLD_SIGNAL_MOBILE;
                            singleItem = new JSONObject();
                            singleItem.put("title", labels.getString("RESULT_SIGNAL"));
                            signalString = signalValue + " " + labels.getString("RESULT_SIGNAL_UNIT");
                            singleItem.put("value", signalString);
                            singleItem.put("classification", Classification.classify(threshold, signalValue));
                        } else { // use RSRP value else (RSRP value has priority if both are available (e.g. 3G/4G-test))
                            final int signalValue = lteRsrpField.intValue();
                            final int[] threshold = classification.THRESHOLD_SIGNAL_RSRP;
                            singleItem = new JSONObject();
                            singleItem.put("title", labels.getString("RESULT_SIGNAL_RSRP"));
                            signalString = signalValue + " " + labels.getString("RESULT_SIGNAL_UNIT");
                            singleItem.put("value", signalString);
                            singleItem.put("classification", Classification.classify(threshold, signalValue));

                        }
                        jsonItemList.put(singleItem);
                    }

                    jsonItem.put("measurement", jsonItemList);

                    jsonItemList = new JSONArray();

                    singleItem = new JSONObject();
                    singleItem.put("title", labels.getString("RESULT_NETWORK_TYPE"));
                    final String networkTypeString = Helperfunctions.getNetworkTypeName(networkType);
                    singleItem.put("value", networkTypeString);

                    jsonItemList.put(singleItem);

                    if (networkType == 98 || networkType == 99) // mobile wifi or browser
                    {
                        final Field providerNameField = test.getField("provider_id_name");
                        if (!providerNameField.isNull()) {
                            singleItem = new JSONObject();
                            singleItem.put("title", labels.getString("RESULT_OPERATOR_NAME"));
                            singleItem.put("value", providerNameField.toString());
                            jsonItemList.put(singleItem);
                        }
                        if (networkType == 99) // mobile wifi
                        {
                            final Field ssid = test.getField("wifi_ssid");
                            if (!ssid.isNull()) {
                                singleItem = new JSONObject();
                                singleItem.put("title", labels.getString("RESULT_WIFI_SSID"));
                                singleItem.put("value", ssid.toString());
                                jsonItemList.put(singleItem);
                            }

                        }
                    } else // mobile
                    {
                        final Field operatorNameField = test.getField("network_operator_name");
                        if (!operatorNameField.isNull()) {
                            singleItem = new JSONObject();
                            singleItem.put("title", labels.getString("RESULT_OPERATOR_NAME"));
                            singleItem.put("value", operatorNameField.toString());
                            jsonItemList.put(singleItem);
                        }

                        final Field roamingTypeField = test.getField("roaming_type");
                        if (!roamingTypeField.isNull() && roamingTypeField.intValue() > 0) {
                            singleItem = new JSONObject();
                            singleItem.put("title", labels.getString("RESULT_ROAMING"));
                            singleItem.put("value",
                                    Helperfunctions.getRoamingType(labels, roamingTypeField.intValue()));
                            jsonItemList.put(singleItem);
                        }
                    }

                    jsonItem.put("net", jsonItemList);

                    final Field latField = test.getField("geo_lat");
                    final Field longField = test.getField("geo_long");
                    boolean includeLocation = false;
                    final Field accuracyField = test.getField("geo_accuracy");
                    if (!(latField.isNull() || longField.isNull() || accuracyField.isNull())) {
                        final double accuracy = accuracyField.doubleValue();
                        if (accuracy < Double.parseDouble(getSetting("rmbt_geo_accuracy_button_limit", lang))) {
                            includeLocation = true;
                            jsonItem.put("geo_lat", latField.doubleValue());
                            jsonItem.put("geo_long", longField.doubleValue());
                        }
                    }

                    //geo location
                    JSONObject locationJson = TestResultDetailResource.getGeoLocation(this, test, settings,
                            conn, labels);
                    if (locationJson != null) {
                        if (locationJson.has("location")) {
                            jsonItem.put("location", locationJson.getString("location"));
                        }
                        if (locationJson.has("motion")) {
                            jsonItem.put("motion", locationJson.getString("motion"));
                        }
                    }

                    resultList.put(jsonItem);

                    final Field zip_code = test.getField("zip_code");
                    if (!zip_code.isNull())
                        jsonItem.put("zip_code", zip_code.intValue());

                    final Field zip_code_geo = test.getField("zip_code_geo");
                    if (!zip_code_geo.isNull())
                        jsonItem.put("zip_code_geo", zip_code_geo.intValue());

                    String providerString = test.getField("provider_id_name").toString();
                    if (providerString == null)
                        providerString = "";
                    String platformString = test.getField("plattform").toString();
                    if (platformString == null)
                        platformString = "";
                    String modelString = test.getField("model_fullname").toString();
                    if (modelString == null)
                        modelString = "";

                    String mobileNetworkString = null;
                    final Field networkOperatorField = test.getField("network_operator");
                    final Field mobileProviderNameField = test.getField("mobile_provider_name");
                    if (!networkOperatorField.isNull()) {
                        if (mobileProviderNameField.isNull())
                            mobileNetworkString = networkOperatorField.toString();
                        else
                            mobileNetworkString = String.format("%s (%s)", mobileProviderNameField,
                                    networkOperatorField);
                    }

                    /*
                    RESULT_SHARE_TEXT = My Result:\nDate/time: {0}\nDownload: {1}\nUpload: {2}\nPing: {3}\n{4}Network type: {5}\n{6}{7}Platform: {8}\nModel: {9}\n{10}\n\n
                    RESULT_SHARE_TEXT_SIGNAL_ADD = Signal strength: {0}\n
                    RESULT_SHARE_TEXT_RSRP_ADD = Signal strength (RSRP): {0}\n
                    RESULT_SHARE_TEXT_MOBILE_ADD = Mobile network: {0}\n
                    RESULT_SHARE_TEXT_PROVIDER_ADD = Operator: {0}\n
                            
                    */
                    String shareTextField4 = "";
                    if (signalString != null) //info on signal strength, field 4
                        if (lteRsrpField.isNull()) { //add RSSI if RSRP is not available
                            shareTextField4 = MessageFormat
                                    .format(labels.getString("RESULT_SHARE_TEXT_SIGNAL_ADD"), signalString);
                        } else { //add RSRP
                            shareTextField4 = MessageFormat
                                    .format(labels.getString("RESULT_SHARE_TEXT_RSRP_ADD"), signalString);
                        }
                    String shareLocation = "";
                    if (includeLocation && locationJson != null) {

                        shareLocation = MessageFormat.format(labels.getString("RESULT_SHARE_TEXT_LOCATION_ADD"),
                                locationJson.getString("location"));
                    }

                    final String shareText = MessageFormat.format(labels.getString("RESULT_SHARE_TEXT"),
                            timeString, //field 0
                            downloadString, //field 1
                            uploadString, //field 2
                            pingString, //field 3
                            shareTextField4, //contains field 4
                            networkTypeString, //field 5
                            providerString.isEmpty() ? ""
                                    : MessageFormat.format(labels.getString("RESULT_SHARE_TEXT_PROVIDER_ADD"),
                                            providerString), //field 6
                            mobileNetworkString == null ? ""
                                    : MessageFormat.format(labels.getString("RESULT_SHARE_TEXT_MOBILE_ADD"),
                                            mobileNetworkString), //field 7
                            platformString, //field 8
                            modelString, //field 9
                            //dz add location
                            shareLocation, //field 10
                            getSetting("url_open_data_prefix", lang) + openTestUUID); //field 11
                    jsonItem.put("share_text", shareText);

                    final String shareSubject = MessageFormat.format(labels.getString("RESULT_SHARE_SUBJECT"),
                            timeString //field 0
                    );
                    jsonItem.put("share_subject", shareSubject);

                    jsonItem.put("network_type", networkType);

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

                    answer.put("testresult", resultList);
                } 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());
        }
    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_TESTRESULT_SUCCESS"), clientIpRaw,
            Long.toString(elapsedTime)));

    return answerString;
}

From source file:org.openvpms.web.resource.i18n.format.DateFormatter.java

/**
 * Returns a date-time format./*from   w  w  w.j a  v a2  s.  c  o  m*/
 *
 * @param edit if {@code true} return a format for editing otherwise
 * @return a format for viewing date-times.
 */
public static DateFormat getDateTimeFormat(boolean edit) {
    DateFormat format;
    Locale locale = Messages.getLocale();
    if (edit) {
        // specify SHORT style for dates when parsing, so that 2 digit years
        // are handled correctly
        format = DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.SHORT, locale);
    } else if (DATE_TIME_VIEW_PATTERN != null) {
        format = new SimpleDateFormat(DATE_TIME_VIEW_PATTERN, locale);
    } else {
        format = DateFormat.getDateTimeInstance(DateFormat.MEDIUM, DateFormat.SHORT, locale);
    }
    return format;
}

From source file:com.expressui.core.view.field.format.DefaultFormats.java

/**
 * Gets date-time format, using current user's locale and default date and time styles defined in
 * application.properties./*  ww  w .j  ava2s  .  co m*/
 *
 * @return default date-time format
 */
public PropertyFormatter getDateTimeFormat() {
    return new JDKBridgePropertyFormatter(
            DateFormat.getDateTimeInstance(applicationProperties.getDefaultDateStyle(),
                    applicationProperties.getDefaultTimeStyle(), MainApplication.getInstance().getLocale()));
}

From source file:DateUtil.java

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

From source file:org.apache.syncope.client.console.SyncopeSession.java

public DateFormat getDateFormat() {
    final Locale locale = getLocale() == null ? Locale.ENGLISH : getLocale();

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

From source file:com.kth.baasio.baassample.utils.EtcUtils.java

public static String getSimpleDateString(long millis) {
    String time = null;//ww  w.j a v  a2 s  . c o m

    if (Locale.getDefault().equals(Locale.KOREA) || Locale.getDefault().equals(Locale.KOREAN)) {
        SimpleDateFormat formatter = new SimpleDateFormat("M d? a h mm", Locale.getDefault());
        time = formatter.format(new Date(millis));
    } else {
        time = DateFormat.getDateTimeInstance(DateFormat.MEDIUM, DateFormat.SHORT, Locale.getDefault())
                .format(new Date(millis));
    }

    return time;
}