Example usage for java.text DateFormat MEDIUM

List of usage examples for java.text DateFormat MEDIUM

Introduction

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

Prototype

int MEDIUM

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

Click Source Link

Document

Constant for medium style pattern.

Usage

From source file:org.sigmah.server.schedule.ReportMailerJob.java

@Inject
public ReportMailerJob(EntityManager em, ReportGenerator reportGenerator, RtfReportRenderer rtfReportRenderer,
        MailSender mailer) {//from   www.j a  va 2 s.  com
    this.em = em;
    this.reportGenerator = reportGenerator;
    this.rtfReportRenderer = rtfReportRenderer;
    this.mailer = mailer;

    reportDateFormat = DateFormat.getDateInstance(DateFormat.MEDIUM);
}

From source file:com.espian.ticktock.CountdownFragment.java

@Override
public void onActivityCreated(Bundle savedInstanceState) {
    super.onActivityCreated(savedInstanceState);

    if (getArguments() == null)
        throw new IllegalArgumentException("No args supplied for fragment");

    try {// w  w w.  jav a  2  s. co  m

        final Date date = DateFormat.getDateInstance(DateFormat.LONG).parse(getArguments().getString("date"));
        mIdAsString = getArguments().getString(BaseColumns._ID);
        mLabelView.setText(mLabel = getArguments().getString("label"));
        mDateView.setText(DateFormat.getDateInstance(DateFormat.MEDIUM).format(date));
        mHelper = new LoadHideHelper(this);

        new Thread(new Runnable() {
            @Override
            public void run() {

                // Requires an ugly fudge because, for some reason, the Days class accesses
                // the disk through random access, which throws errors with StrictMode.
                int days = Days.daysBetween(new DateTime(new Date()), new DateTime(date)).getDays();
                Bundle b = new Bundle();
                b.putString("result", String.valueOf(days + 1));
                Message m = Message.obtain(asyncHandler);
                m.setData(b);
                asyncHandler.sendMessage(m);

            }
        }).start();

    } catch (ParseException e) {
        Toast.makeText(getActivity(), "Malformed date was stored", Toast.LENGTH_SHORT).show();
        e.printStackTrace();
    }

    //getActivity().getLoaderManager().initLoader(TickTockProvider.LOADER_SINGLE_ITEM, getArguments(), this);

}

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

public static String getShortDateFormat(Locale locale) {
    String dateSeparator = DateUtils.getDateSeparatorByLocale(locale, DateFormat.MEDIUM);
    return String.format("dd%sMMM%syyyy", dateSeparator, dateSeparator);
}

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

/**
 * Returns a date format./*from  w ww  .  j  a  va 2  s.  c  o  m*/
 *
 * @param edit if {@code true} return a format for editing otherwise return a format for viewing dates
 * @return a date format
 */
public static DateFormat getDateFormat(boolean edit) {
    DateFormat format;
    Locale locale = Messages.getLocale();
    String pattern = (edit) ? DATE_EDIT_PATTERN : DATE_VIEW_PATTERN;
    if (pattern == null) {
        if (edit) {
            // specify SHORT style when parsing, so that 2 digit years
            // are handled correctly
            format = DateFormat.getDateInstance(DateFormat.SHORT, locale);
        } else {
            format = DateFormat.getDateInstance(DateFormat.MEDIUM, locale);
        }
    } else {
        format = new SimpleDateFormat(pattern, locale);
    }
    return format;
}

From source file:org.kalypso.utils.log.FileLog.java

/**
 * The constructor.//from   w  ww.j a v  a 2  s  .  c  o  m
 * 
 * @param file
 *          The log file. May not be null.
 */
public FileLog(final File file) {
    /* The log file may not be null. */
    Assert.isNotNull(file);

    m_file = file;
    m_df = DateFormat.getDateTimeInstance(DateFormat.MEDIUM, DateFormat.SHORT);
}

From source file:io.lightlink.excel.StreamingExcelExporter.java

/**
 * Override to redefine datetime format (second line of the exported document). Default value is "dd/MM/yyyy HH:mm"
 *
 * @return/*from   w  w w .ja  va  2  s  .c om*/
 */
protected DateFormat getExportDateTimeFormat() {
    String dateFormat = (String) data.get("dateFormat"); // todo getDate from typesFacade
    if (dateFormat == null) {
        return DateFormat.getDateInstance(DateFormat.MEDIUM, Locale.getDefault());
    } else
        return new SimpleDateFormat(dateFormat);
}

From source file:DateFormatDemo.java

static public void showTimeStyles(Locale currentLocale) {

    Date today = new Date();
    String result;/*from   w  w  w .j a  va 2s  . com*/
    DateFormat formatter;

    int[] styles = { DateFormat.DEFAULT, DateFormat.SHORT, DateFormat.MEDIUM, DateFormat.LONG,
            DateFormat.FULL };

    System.out.println();
    System.out.println("Locale: " + currentLocale.toString());
    System.out.println();

    for (int k = 0; k < styles.length; k++) {
        formatter = DateFormat.getTimeInstance(styles[k], currentLocale);
        result = formatter.format(today);
        System.out.println(result);
    }
}

From source file:org.jamwiki.utils.DateUtil.java

/**
 * Given a string, return the matching DateFormat style (SHORT, LONG, etc)
 * or -1 if there is no corresponding style.
 *//*from  w w w .  j a  v a 2s .c om*/
public static int stringToDateFormatStyle(String format) {
    if (StringUtils.equalsIgnoreCase(format, "SHORT")) {
        return DateFormat.SHORT;
    } else if (StringUtils.equalsIgnoreCase(format, "MEDIUM")) {
        return DateFormat.MEDIUM;
    } else if (StringUtils.equalsIgnoreCase(format, "LONG")) {
        return DateFormat.LONG;
    } else if (StringUtils.equalsIgnoreCase(format, "FULL")) {
        return DateFormat.FULL;
    } else if (StringUtils.equalsIgnoreCase(format, "DEFAULT")) {
        return DateFormat.DEFAULT;
    }
    return -1;
}

From source file:com.jslsolucoes.tagria.lib.util.TagUtil.java

public static String format(String type, String value, JspContext jspContext) {

    if (StringUtils.isEmpty(value)) {
        return value;
    } else if ("date".equals(type) || "timestamp".equals(type) || "hour".equals(type)) {

        DateFormat dateFormat = DateFormat.getDateTimeInstance();
        if ("timestamp".equals(type)) {
            dateFormat = DateFormat.getDateTimeInstance(DateFormat.MEDIUM, DateFormat.MEDIUM,
                    locale(jspContext));
        } else if ("date".equals(type)) {
            dateFormat = DateFormat.getDateInstance(DateFormat.MEDIUM, locale(jspContext));
        } else if ("hour".equals(type)) {
            dateFormat = DateFormat.getTimeInstance(DateFormat.MEDIUM, locale(jspContext));
        }/*  w w  w .  j a v  a 2 s. c o m*/
        List<String> patterns = new ArrayList<>();
        patterns.add("yyyy-MM-dd HH:mm:ss");
        patterns.add("yyyy-MM-dd");
        patterns.add("E MMM dd HH:mm:ss zzz yyyy");
        for (String pattern : patterns) {
            try {
                return dateFormat.format(new SimpleDateFormat(pattern, Locale.ENGLISH).parse(value));
            } catch (ParseException pe) {
                //Try another format
            }
        }
        return value;
    } else if ("currency".equals(type)) {
        DecimalFormat nf = new DecimalFormat("#,##0.00", new DecimalFormatSymbols(locale(jspContext)));
        return nf.format(new Double(value));
    } else if ("cep".equals(type)) {
        return String.format("%08d", Long.valueOf(value)).replaceAll("^([0-9]{5})([0-9]{3})$", "$1-$2");
    } else if ("cpf".equals(type)) {
        return String.format("%011d", Long.valueOf(value))
                .replaceAll("^([0-9]{3})([0-9]{3})([0-9]{3})([0-9]{2})$", "$1.$2.$3-$4");
    } else if ("cnpj".equals(type)) {
        return String.format("%014d", Long.valueOf(value))
                .replaceAll("^([0-9]{2})([0-9]{3})([0-9]{3})([0-9]{4})([0-9]{2})$", "$1.$2.$3/$4-$5");
    } else if ("tel".equals(type)) {
        return String.format("%010d", Long.valueOf(value)).replaceAll("^([0-9]{2})([0-9]{4,5})([0-9]{4})$",
                "($1) $2-$3");
    }
    return value;
}

From source file:org.openmrs.web.dwr.DrugOrderListItem.java

public DrugOrderListItem(DrugOrder drugOrder) {
    orderId = drugOrder.getOrderId();/*  w  ww  . j a  v a 2  s .  c om*/
    if (drugOrder.getConcept() != null) {
        conceptId = drugOrder.getConcept().getConceptId();
        conceptName = drugOrder.getConcept().getName().getName();
    }
    instructions = drugOrder.getInstructions();

    DateFormat df = DateFormat.getDateInstance(DateFormat.MEDIUM, Context.getLocale());

    if (drugOrder.getStartDate() != null)
        startDate = df.format(drugOrder.getStartDate());
    if (drugOrder.getAutoExpireDate() != null)
        autoExpireDate = df.format(drugOrder.getAutoExpireDate());
    if (drugOrder.getEncounter() != null)
        encounterId = drugOrder.getEncounter().getEncounterId();
    if (drugOrder.getOrderer() != null)
        ordererId = drugOrder.getOrderer().getProviderId();
    discontinued = drugOrder.getDiscontinued();
    if (drugOrder.getDiscontinuedBy() != null)
        discontinuerId = drugOrder.getDiscontinuedBy().getUserId();
    if (drugOrder.getDiscontinuedDate() != null)
        discontinuedDate = df.format(drugOrder.getDiscontinuedDate());
    if (drugOrder.getDiscontinuedReason() != null)
        discontinueReason = drugOrder.getDiscontinuedReason();
    if (drugOrder.getDrug() != null)
        drugId = drugOrder.getDrug().getDrugId();
    if (drugOrder.getDrug() != null)
        drugName = drugOrder.getDrug().getName();
    dose = drugOrder.getDose();
    doseUnits = drugOrder.getDoseUnits();
    frequency = drugOrder.getFrequency();
    asNeeded = drugOrder.getAsNeeded();
    quantity = drugOrder.getQuantity();
    voided = drugOrder.getVoided();
    if (drugOrder.getVoidedBy() != null)
        voiderId = drugOrder.getVoidedBy().getUserId();
    if (drugOrder.getDateVoided() != null)
        voidedDate = df.format(drugOrder.getDateVoided());
    voidReason = drugOrder.getVoidReason();
    if (drugOrder.getCreator() != null)
        creatorId = drugOrder.getCreator().getUserId();
    if (drugOrder.getDateCreated() != null)
        createdDate = df.format(drugOrder.getDateCreated());
}