Android Date String to Date Convert getShortDateTimeString(String date, Locale locale)

Here you can find the source of getShortDateTimeString(String date, Locale locale)

Description

get Short Date Time String

Declaration

public static String getShortDateTimeString(String date, Locale locale) 

Method Source Code

//package com.java2s;
import java.text.DateFormat;

import java.util.Date;
import java.util.HashMap;
import java.util.Locale;
import java.util.Map;

public class Main {
    private static final Map<String, DateFormat> dateFormats = new HashMap<String, DateFormat>();

    public static String getShortDateTimeString(long date, Locale locale) {
        return getDateTimeString(new Date(date), DateFormat.SHORT, locale);
    }/*from  w w w.j a va  2  s .  c o m*/

    public static String getShortDateTimeString(String date, Locale locale) {
        try {
            long millis = Long.parseLong(date);
            return getDateTimeString(new Date(millis), DateFormat.SHORT,
                    locale);
        } catch (Exception e) {
            return "";
        }
    }

    private static String getDateTimeString(Date date, int format,
            Locale currentLocale) {

        String key = format + "_" + currentLocale.toString();

        DateFormat formatter = dateFormats.get(key);

        if (formatter == null) {
            formatter = DateFormat.getDateTimeInstance(format, format,
                    currentLocale);
            dateFormats.put(key, formatter);
        }

        return formatter.format(date);
    }
}

Related

  1. formatToDate(String date)
  2. fromStringFR(String dateString)
  3. fromStringUS(String dateString)
  4. getDateFromString(String dateString, String dateFormat)
  5. getDefaultDateTimeString(String date, Locale locale)
  6. iso8601ToTimestamp(final String strDate)
  7. iso8601ToTimestamp(final String strDate)
  8. parseCalDav(String date)
  9. parseCalDavDue(String date)