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

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

Description

get Short Date Time String

Declaration

public static String getShortDateTimeString(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 getShortDateTimeString(long date, Locale locale) {
        return getDateTimeString(new Date(date), DateFormat.SHORT, locale);
    }//from   w  w  w. j ava 2s  .  co 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. getReadableTimeStamp(long timeStamp)
  2. getReadableTimeUsage(long timeUsageMs)
  3. getRelativeDateLabel(long time)
  4. getRelativeTimeFromMilliSeconds(long dateInMillis)
  5. getShortDateString(long date, Locale locale)
  6. getSimpleDatetime(long milliseconds)
  7. getStandardTime(long timestamp)
  8. getStartTimeOfDay(long timeInLong)
  9. getStringOfLong(long date)