Android examples for java.util:Date Format
Displays a passed in Date value (date only) according to the preferred date format
import android.content.Context; import android.util.Log; import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.Calendar; import java.util.Date; import java.util.GregorianCalendar; import java.util.Locale; public class Main{ /**/* w w w . j ava 2 s . c o m*/ * Displays a passed in Date value (date only) according to the preferred date format. * @param context The Context that will be passed into the getDefaultSharedPreferences routine. * @param date The Date that will be displayed. * @return A String value that represents the passed in date according to the preferred format. * @see DateUtil#displayDateTime(android.content.Context, * java.util.Date) displayDateTime returns a formatted string that includes the time value. */ public static String displayDate(Context context, Date date) { // SharedPreferences sharedPref = PreferenceManager.getDefaultSharedPreferences(context); // String dateFormat = sharedPref.getString(SettingsActivity.PREF_DATE_FORMAT, "MM/dd/yyyy"); // SimpleDateFormat sdf = new SimpleDateFormat(dateFormat, Locale.US); // return sdf.format(date); return android.text.format.DateFormat.getDateFormat(context) .format(date); } }