Android Long to Date Convert getDefaultDateTimeString(long date, Locale locale)

Here you can find the source of getDefaultDateTimeString(long date, Locale locale)

Description

get Default Date Time String

Declaration

public static String getDefaultDateTimeString(long 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 getDefaultDateTimeString(long date, Locale locale) {
        return getDateTimeString(new Date(date), DateFormat.DEFAULT, locale);
    }/*from w  w w.j  av  a2  s.c om*/

    public static String getDefaultDateTimeString(String date, Locale locale) {
        try {
            long millis = Long.parseLong(date);
            return getDateTimeString(new Date(millis), DateFormat.DEFAULT,
                    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. getDateTimeLabel(long time)
  2. getDateTimeString(long dateTime)
  3. getDateWeekLabel(long date)
  4. getDay(long dateTimeMillis)
  5. getDayOfWeek(long timeMillis)
  6. getDefaultDatetime(long milliseconds)
  7. getElapsedDurationSince(long seconds)
  8. getFormattedTime(String dateTimeFormat, long timestamp)
  9. getFriendlyDate(Context context, long timestamp)