Android Date Format formatDate(String date)

Here you can find the source of formatDate(String date)

Description

format Date, "yyyy/MM/dd"

Declaration

@SuppressLint("SimpleDateFormat")
    public static String formatDate(String date) 

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")
    public static String formatDate(String date) {
        SimpleDateFormat sdf = new SimpleDateFormat(FORMAT_DATE_YYYY_MM_DD);

        String newKey;// w w  w.  j  a  v a2 s. c o  m
        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)
  3. formatDate(Date date, String pattern, TimeZone zone)
  4. formatDate(Date time)
  5. formatDate(SimpleDateFormat s, Date d)
  6. formatDate(long millis)
  7. formatDate1(String date)
  8. formatDateAndTime(long millis)
  9. formatTM(Date d)