Here you can find the source of formatDateTime(long timeToFormatInMilliseconds)
public static String formatDateTime(long timeToFormatInMilliseconds)
//package com.java2s; import java.text.SimpleDateFormat; import java.util.Date; import java.util.TimeZone; import android.content.Context; public class Main { public static String formatDateTime(Context context, String timeToFormat) { String finalDateTime = ""; SimpleDateFormat iso8601Format = new SimpleDateFormat( "yyyy-MM-dd HH:mm:ss"); Date date = null;//from w ww .j a v a 2 s . co m if (timeToFormat != null) { try { date = iso8601Format.parse(timeToFormat); } catch (Exception e) { date = null; } if (date != null) { long when = date.getTime(); int flags = 0; flags |= android.text.format.DateUtils.FORMAT_SHOW_TIME; flags |= android.text.format.DateUtils.FORMAT_SHOW_DATE; flags |= android.text.format.DateUtils.FORMAT_ABBREV_MONTH; flags |= android.text.format.DateUtils.FORMAT_SHOW_YEAR; finalDateTime = android.text.format.DateUtils .formatDateTime(context, when + TimeZone.getDefault().getOffset(when), flags); } } return finalDateTime; } public static String formatDateTime(long timeToFormatInMilliseconds) { /*SimpleDateFormat iso8601Format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); Date date = iso8601Format.parse(timeToFormatInMilliseconds);*/ SimpleDateFormat formatter = new SimpleDateFormat( "MM/dd/yyyy hh:mm:ss a"); formatter.setTimeZone(TimeZone.getDefault()); String currentDate = formatter.format(timeToFormatInMilliseconds); return currentDate; } }