Android examples for java.util:Date Format
Format Date in yyyy-MM-dd HH:mm:ss format
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; } }