Android examples for java.util:Date Format
format Date to string in yyyy/MM/dd HH:mm:ss format, till second
import android.util.Log; import java.io.File; import java.text.DecimalFormat; import java.text.NumberFormat; import java.text.SimpleDateFormat; import java.util.Date; public class Main{ public static String formatDate(long time) { SimpleDateFormat sdf = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss"); java.util.Date dt = new Date(time); String sDateTime = sdf.format(dt); return sDateTime; }/*from ww w. java 2 s.co m*/ public static String formatDate(Date date) { if (date != null) { return formatDate(date.getTime()); } return ""; } }