How to set TimePicker show with format 24h

I’ve created a TimePicker in layout and I want it to show time with format 24h.

Can you help me? Thanks.

  • Why declare a function argument to be final?
  • adb forward remote port to local machine
  • Significance of in build path?
  • How to learn and use OpenGL ES 2.0? I just don't get it - serious Qn.
  • Pass list of objects from one activity to other activity in android
  • scale fit mobile web content using viewport meta tag
  • How to show image using ImageView in Android
  • Dialog problem: requestFeature() must be called before adding content
  • Android actionbar how to add supporting library v7 appcompat for Eclipse
  • Provide secure Facebook authentication with my Server
  • Android Bluetooth logging filling up logcat
  • Google Map API V2 - How do I keep a marker in the center of the screen while user is scrolling the map?
  • 9 Solutions collect form web for “How to set TimePicker show with format 24h”

    TimePicker is a view for selecting the time of day, in either 24 hour or AM/PM mode.
    You can use setIs24HourView(true) method with TimePicker.

    Setting TimePicker by default to 24 hour mode is not always a good idea since many countrys have diffrent convention. For this case use DateFormat.is24HourFormat(getActivity()).

    Your final code migth look like picker.setIs24HourView(DateFormat.is24HourFormat(this));.

    Further details see:

    If you want the TimePicker to be correctly initialized with the current time in 24h format use the following:

    import java.util.Calendar;

    Otherwise, due to Android bug, the picker will start with an incorrect hour (2 instead of 14 etc).

    You just have to retrieve the TimePicker instance from the view after inflating it, then you can modify the widget.

    Ids are arbitrary:

    View v=getActivity().getLayoutInflater().inflate(R.layout.dialog_time, null);
    TimePicker timePicker=(TimePicker)v.findViewById(;


            android:id="@+id/timePicker" />


    TimePicker timePicker = (TimePicker) findViewById(;    

    By default, it displays time in the AM/PM format. If you want to change time in the 24 hour format, then you can use the setIs24HourView() method.
    See this link:

    You just need call and send true to setIs24HourView function.

    TimePicker tpHourMin = (TimePicker) findViewById(;

    As some people have already mentioned just set the parameter to true or false.


    You can find a complete example with source code to download from here

    I need the same just for an application to set the duration spend for doing a task. I found that I just need to extend the TimePickerDialog class and pass True in the last constructor parameter boolean is24HourView.

    public class DurationPickerDialog extends TimePickerDialog {
    public DurationPickerDialog(Context context, TimePickerDialog.OnTimeSetListener callBack, int hourOfDay, int minute){
        super(context, callBack, hourOfDay, minute, true);

    Then you only need to create this as

    TimePickerDialog durationPicker =  new DurationPickerDialog(getActivity(), this, hour, minute);
    Android Babe is a Google Android Fan, All about Android Phones, Android Wear, Android Dev and Android Games Apps and so on.