Example usage for java.text DateFormat SHORT

List of usage examples for java.text DateFormat SHORT

Introduction

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

Prototype

int SHORT

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

Click Source Link

Document

Constant for short style pattern.

Usage

From source file:de.nico.ha_manager.activities.AddHomework.java

private void setTextViewUntil(int[] date) {
    // Format to 31.12.14 or local version of that
    DateFormat f = DateFormat.getDateInstance(DateFormat.SHORT, Locale.getDefault());
    GregorianCalendar gc = new GregorianCalendar(date[0], date[1], date[2]);
    until = f.format(gc.getTime());//  www . j  a v  a2s  .co  m

    // Format to Week of Day, for example Mo. or local version of that
    SimpleDateFormat dateFormat = new SimpleDateFormat("EEE", Locale.getDefault());
    String asWeek = dateFormat.format(gc.getTime());

    // Tab space because else the date is too far to the left
    until = (asWeek + ", " + until);
    Button untilButton = (Button) findViewById(R.id.button_until);
    untilButton.setText(until);

}

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

/**
 * Returns a time format.//w w w.  j a va  2s  .  c  om
 * <p/>
 * This will use the <em>time.format.edit</em> and <em>time.format.view</em> properties if specified in
 * <em>messages.properties</em>, else it will fall back to those provided by the locale.
 *
 * @param edit if {@code true} return a format for editing otherwise
 *             return a format for viewing dates
 * @return a date format
 */
public static DateFormat getTimeFormat(boolean edit) {
    DateFormat format;
    Locale locale = Messages.getLocale();
    String pattern = (edit) ? TIME_EDIT_PATTERN : TIME_VIEW_PATTERN;
    if (pattern == null) {
        if (edit) {
            // specify SHORT style when parsing, so that 2 digit years
            // are handled correctly
            format = DateFormat.getTimeInstance(DateFormat.SHORT, locale);
        } else {
            format = DateFormat.getTimeInstance(DateFormat.MEDIUM, locale);
        }
    } else {
        format = new SimpleDateFormat(pattern, locale);
    }
    return format;
}

From source file:org.mifos.framework.util.helpers.DateUtils.java

public static String getUserLocaleDate(Locale locale, String databaseDate) {
    // the following line is for 1.1 release and will be removed when date
    // is localized
    locale = internalLocale;//from w  ww . java 2  s.co  m
    if (locale != null && databaseDate != null && !databaseDate.equals("")) {
        try {
            SimpleDateFormat shortFormat = (SimpleDateFormat) DateFormat.getDateInstance(DateFormat.SHORT,
                    locale);
            String userfmt = convertToCurrentDateFormat(shortFormat.toPattern());
            return convertDbToUserFmt(databaseDate, userfmt);
        } catch (FrameworkRuntimeException e) {
            throw e;
        } catch (Exception e) {
            System.out.println("databaseDate=" + databaseDate + ", locale=" + locale);
            throw new FrameworkRuntimeException(e);
        }
    } else {
        return "";
    }
}

From source file:org.olat.core.util.StringHelper.java

/**
 * @param time/*  w  w  w  .  j a v a 2s.co m*/
 * @param locale
 * @return formatted time
 */
public static String formatLocaleTime(long time, Locale locale) {
    if (time == -1)
        return "-";
    return DateFormat.getTimeInstance(DateFormat.SHORT, locale).format(new Date(time));
}

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

public static String getSimpleDateString(long millis) {
    String time = null;/*from www.j av a  2 s.c  o m*/

    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.telscenter.sail.webapp.presentation.web.controllers.student.brainstorm.XMLBrainstorm.java

public static String getXMLComment(Comment comment) {
    Date timestamp = comment.getTimestamp();
    String formattedTime = DateFormat.getTimeInstance(DateFormat.SHORT).format(timestamp);

    String formattedDate = DateFormat.getDateInstance(DateFormat.MEDIUM).format(timestamp);

    String XMLComment = "<comment><id>" + comment.getId() + "</id><timestamp>" + formattedTime + " "
            + formattedDate + "</timestamp>" + getXMLWorkgroup(comment.getWorkgroup()) + "<body>"
            + StringEscapeUtils.escapeHtml(comment.getBody()) + "</body><anon>" + comment.isAnonymous()
            + "</anon></comment>";
    return XMLComment;
}

From source file:de.uni_koeln.spinfo.maalr.webapp.controller.EditorController.java

@RequestMapping("/editor/export")
public void export(@RequestParam(value = "all", defaultValue = "true") boolean allVersions,
        @RequestParam(value = "dropKeys", defaultValue = "false") boolean dropKeys,
        HttpServletResponse response)/* ww  w .  jav  a2 s. co m*/
        throws IOException, NoDatabaseAvailableException, JAXBException, NoSuchAlgorithmException {
    response.setContentType("application/zip");
    StringBuilder fileName = new StringBuilder();
    fileName.append("maalr_db_dump_");
    if (allVersions) {
        fileName.append("all_versions_");
    } else {
        fileName.append("current_versions_");
    }
    if (dropKeys) {
        fileName.append("anonymized_");
    }
    fileName.append(DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.SHORT).format(new Date()));
    response.setHeader("Content-Disposition", "attachment; filename=" + fileName + ".zip");
    ServletOutputStream out = response.getOutputStream();
    service.exportData(allVersions, dropKeys, out, fileName.toString());
}

From source file:org.mariotaku.twidere.adapter.DirectMessagesEntryAdapter.java

@Override
public void bindView(final View view, final Context context, final Cursor cursor) {
    final DirectMessageEntryViewHolder holder = (DirectMessageEntryViewHolder) view.getTag();

    final long account_id = cursor.getLong(ConversationsEntry.IDX_ACCOUNT_ID);
    final long conversation_id = cursor.getLong(ConversationsEntry.IDX_CONVERSATION_ID);
    final long message_timestamp = cursor.getLong(ConversationsEntry.IDX_MESSAGE_TIMESTAMP);
    final boolean is_outgoing = cursor.getInt(ConversationsEntry.IDX_IS_OUTGOING) == 1;

    final String name = cursor.getString(IDX_NAME);
    final String screen_name = cursor.getString(IDX_SCREEN_NAME);

    holder.setAccountColorEnabled(mShowAccountColor);

    if (mShowAccountColor) {
        holder.setAccountColor(getAccountColor(mContext, account_id));
    }//from   www  . jav  a2  s  . co  m

    if (!mFastProcessingEnabled) {
        holder.setUserColor(getUserColor(mContext, conversation_id));
    } else {
        holder.setUserColor(Color.TRANSPARENT);
    }

    holder.setTextSize(mTextSize);
    switch (mNameDisplayOption) {
    case NAME_DISPLAY_OPTION_CODE_NAME: {
        holder.name.setText(name);
        holder.screen_name.setText(null);
        holder.screen_name.setVisibility(View.GONE);
        break;
    }
    case NAME_DISPLAY_OPTION_CODE_SCREEN_NAME: {
        holder.name.setText("@" + screen_name);
        holder.screen_name.setText(null);
        holder.screen_name.setVisibility(View.GONE);
        break;
    }
    default: {
        holder.name.setText(name);
        holder.screen_name.setText("@" + screen_name);
        holder.screen_name.setVisibility(View.VISIBLE);
        break;
    }
    }
    holder.text.setText(toPlainText(cursor.getString(IDX_TEXT)));
    if (mShowAbsoluteTime) {
        holder.time.setText(formatSameDayTime(message_timestamp, System.currentTimeMillis(), DateFormat.MEDIUM,
                DateFormat.SHORT));
    } else {
        holder.time.setText(getRelativeTimeSpanString(message_timestamp));
    }
    holder.time.setCompoundDrawablesWithIntrinsicBounds(0, 0,
            is_outgoing ? R.drawable.ic_indicator_outgoing : R.drawable.ic_indicator_incoming, 0);
    holder.profile_image.setVisibility(mDisplayProfileImage ? View.VISIBLE : View.GONE);
    if (mDisplayProfileImage) {
        final String profile_image_url_string = cursor.getString(IDX_PROFILE_IMAGE_URL);
        mProfileImageLoader.displayImage(holder.profile_image, profile_image_url_string);
    }

    super.bindView(view, context, cursor);
}

From source file:org.olat.core.util.StringHelper.java

/**
 * /*from   w  ww  .j  ava 2 s  . com*/
 * @param time
 * @param locale
 * @return
 */
public static String formatLocaleTime(Date time, Locale locale) {
    if (time == null)
        return "-";
    return DateFormat.getTimeInstance(DateFormat.SHORT, locale).format(time);
}