Android examples for java.util:Hour
Gets android formatter based on current Context and users Android OS preferences (AM/PM vs 24-hour).
//package com.java2s; import java.text.DateFormat; import java.text.SimpleDateFormat; import java.util.Locale; import android.content.Context; public class Main { /**/*from w w w . j ava 2s .c o m*/ * Gets android formatter based on current Context and users AndroidOS preferences (AM/PM vs 24-hour). * @param context Context entity. * @return DateFormat entity with formatting set. */ private static DateFormat getFormatter(Context context) { String format = android.text.format.DateFormat .is24HourFormat(context) ? "HH:mm" : "hh:mmaa"; return new SimpleDateFormat(format, Locale.getDefault()); } }