Android Date Format formatDate(long millis)

Here you can find the source of formatDate(long millis)

Description

format Date

Declaration

public static String formatDate(long millis) 

Method Source Code

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import android.annotation.SuppressLint;

public class Main{
    private static final String FORMAT_DATE_YYYY_MM_DD = "yyyy-MM-dd";
    private static final String FORMAT_DATE_YYYY_MM_DD2 = "yyyy/MM/dd";
    @SuppressLint("SimpleDateFormat")
    /**?????Sting ??date*/
    public static String formatDate(String date) {
        SimpleDateFormat sdf = new SimpleDateFormat(FORMAT_DATE_YYYY_MM_DD);

        String newKey;// w w  w .  jav  a2s .c  om
        if (StringUtils.isEmpty(date) || date.equals("0")) {
            return "";
        } else {
            newKey = date;
        }
        Date dt = new Date(Long.parseLong(newKey));
        String sDateTime = null;

        sDateTime = sdf.format(dt);
        return sDateTime;
    }
    public static String formatDate(long millis) {
        if (millis == 0)
            return "";
        SimpleDateFormat sdf = new SimpleDateFormat(FORMAT_DATE_YYYY_MM_DD2);
        Date dt = new Date(millis);
        String sDateTime = null;

        sDateTime = sdf.format(dt);
        return sDateTime;
    }
}

Related

  1. formatDate(Date date, String pattern)
  2. formatDate(Date date, String pattern, TimeZone zone)
  3. formatDate(Date time)
  4. formatDate(SimpleDateFormat s, Date d)
  5. formatDate(String date)
  6. formatDate1(String date)
  7. formatDateAndTime(long millis)
  8. formatTM(Date d)
  9. fromString(String dateStr)