List of usage examples for android.text.format DateFormat is24HourFormat
public static boolean is24HourFormat(Context context)
From source file:Main.java
public static String toStringReadableTime(Calendar calendar, Context context) { if (DateFormat.is24HourFormat(context)) { return READABLE_TIME_24_FORMAT.format(calendar.getTime()); } else {/* www . ja v a 2s . c o m*/ return READABLE_TIME_FORMAT.format(calendar.getTime()); } }
From source file:Main.java
public static String getLocalizedHHMMStamp(Context context, Date date) { // Different formatters for 12 and 24 hour timestamps SimpleDateFormat formatter24 = new SimpleDateFormat("HH:mm"); SimpleDateFormat formatter12 = new SimpleDateFormat("hh:mm a"); // According to users preferences the OS clock is displayed in 24 hour format if (DateFormat.is24HourFormat(context)) { return formatter24.format(date); }/*from ww w . j a va2 s. c o m*/ return formatter12.format(date); }
From source file:Main.java
public static boolean getSystemTime_12_24(Context context) { if (DateFormat.is24HourFormat(context)) { return true; }// w w w . ja v a2 s .co m return false; }
From source file:Main.java
public static String getFormattedTime(Context context, Calendar time) { String skeleton = DateFormat.is24HourFormat(context) ? "EHm" : "Ehma"; String pattern = DateFormat.getBestDateTimePattern(Locale.getDefault(), skeleton); return (String) DateFormat.format(pattern, time); }
From source file:Main.java
public static void init(@NonNull final Context context) { if (DateFormat.is24HourFormat(context)) { sFormat = new SimpleDateFormat("dd/MM/yyyy HH:mm", Locale.getDefault()); } else {/*w ww. j a v a 2 s. c o m*/ sFormat = new SimpleDateFormat("dd/MM/yyyy KK:mm aa", Locale.getDefault()); } }
From source file:Main.java
public static SimpleDateFormat getDetailedDateFormatter(Context context, Locale locale) { String dateFormatPattern;/*w w w . j av a 2 s . com*/ if (DateFormat.is24HourFormat(context)) { dateFormatPattern = getLocalizedPattern("MMM d, yyyy HH:mm:ss zzz", locale); } else { dateFormatPattern = getLocalizedPattern("MMM d, yyyy hh:mm:ss a zzz", locale); } return new SimpleDateFormat(dateFormatPattern, locale); }
From source file:Main.java
/** * Formats given hours and minutes to 24 / 12 hours format * (depends on current system settings.) * * @return Formatted string time//from w ww. j av a 2 s . co m */ @NonNull public static String formatTime(@NonNull Context context, int h, int m) { if (!DateFormat.is24HourFormat(context)) { // 24h formatting if (h == 0) h = 12; else if (h >= 13) h -= 12; } return h + ":" + (m < 10 ? "0" + m : m); }
From source file:Main.java
public static void setTime(Activity activity, TextView view, long millis) { int flags = DateUtils.FORMAT_SHOW_TIME; flags |= DateUtils.FORMAT_CAP_NOON_MIDNIGHT; if (DateFormat.is24HourFormat(activity)) { flags |= DateUtils.FORMAT_24HOUR; }// ww w . j av a2 s . c o m // Unfortunately, DateUtils doesn't support a timezone other than the // default timezone provided by the system, so we have this ugly hack // here to trick it into formatting our time correctly. In order to // prevent all sorts of craziness, we synchronize on the TimeZone class // to prevent other threads from reading an incorrect timezone from // calls to TimeZone#getDefault() // TODO fix this if/when DateUtils allows for passing in a timezone String timeString; synchronized (TimeZone.class) { timeString = DateUtils.formatDateTime(activity, millis, flags); TimeZone.setDefault(null); } view.setTag(millis); view.setText(timeString); }
From source file:com.facebook.react.modules.timepicker.TimePickerDialogFragment.java
static Dialog createDialog(Bundle args, Context activityContext, @Nullable OnTimeSetListener onTimeSetListener) { final Calendar now = Calendar.getInstance(); int hour = now.get(Calendar.HOUR_OF_DAY); int minute = now.get(Calendar.MINUTE); boolean is24hour = DateFormat.is24HourFormat(activityContext); TimePickerMode mode = TimePickerMode.DEFAULT; if (args != null && args.getString(TimePickerDialogModule.ARG_MODE, null) != null) { mode = TimePickerMode.valueOf(args.getString(TimePickerDialogModule.ARG_MODE).toUpperCase(Locale.US)); }//from w w w.j a va2s .c om if (args != null) { hour = args.getInt(TimePickerDialogModule.ARG_HOUR, now.get(Calendar.HOUR_OF_DAY)); minute = args.getInt(TimePickerDialogModule.ARG_MINUTE, now.get(Calendar.MINUTE)); is24hour = args.getBoolean(TimePickerDialogModule.ARG_IS24HOUR, DateFormat.is24HourFormat(activityContext)); } if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { if (mode == TimePickerMode.CLOCK) { return new DismissableTimePickerDialog( activityContext, activityContext.getResources().getIdentifier("ClockTimePickerDialog", "style", activityContext.getPackageName()), onTimeSetListener, hour, minute, is24hour); } else if (mode == TimePickerMode.SPINNER) { return new DismissableTimePickerDialog( activityContext, activityContext.getResources().getIdentifier("SpinnerTimePickerDialog", "style", activityContext.getPackageName()), onTimeSetListener, hour, minute, is24hour); } } return new DismissableTimePickerDialog(activityContext, onTimeSetListener, hour, minute, is24hour); }
From source file:com.matthewmitchell.wakeifyplus.TimePickerFragment.java
@Override public Dialog onCreateDialog(Bundle savedInstanceState) { // Create a new instance of TimePickerDialog and return it return new TimePickerDialog(getActivity(), (OnTimeSetListener) activity, hour, minute, DateFormat.is24HourFormat(getActivity())); }