Format Date in yyyy-MM-dd HH:mm:ss format - Android java.util

Android examples for java.util:Date Format

Description

Format Date in yyyy-MM-dd HH:mm:ss format

Demo Code

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

public class Main{

    public static String getFormateDate(Date date) {

        SimpleDateFormat formatter = new SimpleDateFormat(
                "yyyy-MM-dd HH:mm:ss");
        String daString = "";
        if (date != null) {
            daString = formatter.format(date);
        }/*from w w w .  j  a va 2s. co m*/
        return daString;
    }
    public static String getFormateDate(Date date, String format) {

        SimpleDateFormat formatter = new SimpleDateFormat(format);
        String daString = "";
        if (date != null) {
            daString = formatter.format(date);
        }
        return daString;
    }

}

Related Tutorials