Here you can find the source of dateToString(String format, String date)
public static String dateToString(String format, String date)
//package com.java2s; import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.Calendar; import java.util.Date; import android.annotation.SuppressLint; public class Main { public static Calendar calendar = Calendar.getInstance(); public static String DEFAULT_DATE_FORMAT = "yyyy-MM-dd HH:mm:ss"; public static String dateToString(Date date) { return dateToString(DEFAULT_DATE_FORMAT, date); }/*w w w . java 2 s .c o m*/ public static String dateToString(String format, String date) { long time = getTimeInMillis(date); calendar.clear(); calendar.setTimeInMillis(time); return dateToString(format, calendar.getTime()); } public static String dateToString(String format, Date date) { SimpleDateFormat dateFormat = new SimpleDateFormat(format); return dateFormat.format(date); } @SuppressLint("SimpleDateFormat") public static long getTimeInMillis(String date) { Date currentDate; try { String format = "HH:mm"; if (date.contains("-")) { format = "yyyy-MM-dd HH:mm:ss"; } SimpleDateFormat dateForamt = new SimpleDateFormat(format); currentDate = dateForamt.parse(date); } catch (ParseException e) { e.printStackTrace(); currentDate = new Date(); } calendar.setTime(currentDate); return calendar.getTimeInMillis(); } }