Example usage for java.text DateFormat getDateInstance

List of usage examples for java.text DateFormat getDateInstance

Introduction

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

Prototype

public static final DateFormat getDateInstance(int style) 

Source Link

Document

Gets the date formatter with the given formatting style for the default java.util.Locale.Category#FORMAT FORMAT locale.

Usage

From source file:org.eclipse.ecr.core.api.AbstractSession.java

protected String oldLockKey(Lock lock) {
    if (lock == null) {
        return null;
    }/*from  ww  w .  j  ava2s. c  o m*/
    // return deprecated format, like "someuser:Nov 29, 2010"
    return lock.getOwner() + ':' + DateFormat.getDateInstance(DateFormat.MEDIUM)
            .format(new Date(lock.getCreated().getTimeInMillis()));
}

From source file:com.codename1.impl.android.AndroidImplementation.java

/**
 * @inheritDoc/*w w  w . j  a  v  a2  s.  co m*/
 */
public L10NManager getLocalizationManager() {
    if (l10n == null) {
        Locale l = Locale.getDefault();
        l10n = new L10NManager(l.getLanguage(), l.getCountry()) {
            public double parseDouble(String localeFormattedDecimal) {
                try {
                    return NumberFormat.getNumberInstance().parse(localeFormattedDecimal).doubleValue();
                } catch (ParseException err) {
                    return Double.parseDouble(localeFormattedDecimal);
                }
            }

            public String format(int number) {
                return NumberFormat.getNumberInstance().format(number);
            }

            public String format(double number) {
                return NumberFormat.getNumberInstance().format(number);
            }

            public String formatCurrency(double currency) {
                return NumberFormat.getCurrencyInstance().format(currency);
            }

            public String formatDateLongStyle(Date d) {
                return DateFormat.getDateInstance(DateFormat.LONG).format(d);
            }

            public String formatDateShortStyle(Date d) {
                return DateFormat.getDateInstance(DateFormat.SHORT).format(d);
            }

            public String formatDateTime(Date d) {
                return DateFormat.getDateTimeInstance().format(d);
            }

            public String formatDateTimeMedium(Date d) {
                DateFormat dd = DateFormat.getDateTimeInstance(DateFormat.MEDIUM, DateFormat.MEDIUM);
                return dd.format(d);
            }

            public String formatDateTimeShort(Date d) {
                DateFormat dd = DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.SHORT);
                return dd.format(d);
            }

            public String getCurrencySymbol() {
                return NumberFormat.getInstance().getCurrency().getSymbol();
            }

            public void setLocale(String locale, String language) {
                super.setLocale(locale, language);
                Locale l = new Locale(language, locale);
                Locale.setDefault(l);
            }
        };
    }
    return l10n;
}

From source file:com.zimbra.cs.account.ProvUtil.java

private void doGetRightsDoc(String[] args) throws ServiceException {
    if (!(prov instanceof SoapProvisioning)) {
        throwSoapOnly();//from  w ww.  jav a 2  s  . c  o  m
    }
    String[] packages;

    StringBuilder argsDump = new StringBuilder();
    if (args.length > 1) {
        // args[0] is "grd", starting from args[1]
        packages = new String[args.length - 1];
        for (int i = 1; i < args.length; i++) {
            packages[i - 1] = args[i];
            argsDump.append(" " + args[i]);
        }
    } else {
        packages = new String[] { "com.zimbra.cs.service.admin", "com.zimbra.bp", "com.zimbra.cert",
                "com.zimbra.cs.network", "com.zimbra.cs.network.license.service",
                "com.zimbra.cs.service.backup", "com.zimbra.cs.service.hsm", "com.zimbra.xmbxsearch" };
    }

    console.println("#");
    console.println("#  Generated by: zmprov grd" + argsDump);
    console.println("#");
    console.println("#  Date: " + DateFormat.getDateInstance(DateFormat.LONG).format(new Date()));
    console.println("# ");
    console.println("#  Packages:");
    for (String pkg : packages) {
        console.println("#       " + pkg);
    }
    console.println("# ");
    console.println("\n");

    Map<String, List<RightsDoc>> allDocs = prov.getRightsDoc(packages);
    for (Map.Entry<String, List<RightsDoc>> docs : allDocs.entrySet()) {
        console.println("========================================");
        console.println("Package: " + docs.getKey());
        console.println("========================================");
        console.println();

        for (RightsDoc doc : docs.getValue()) {
            console.println("------------------------------");
            console.println(doc.getCmd() + "\n");

            console.println("    Related rights:");
            for (String r : doc.getRights()) {
                console.println("        " + r);
            }
            console.println();
            console.println("    Notes:");
            for (String n : doc.getNotes()) {
                console.println(FileGenUtil.wrapComments(StringUtil.escapeHtml(n), 70, "        ") + "\n");
            }
            console.println();
        }
    }
}