how to change the military time in eclipse to 12-hour android

261 Views Asked by At

I don't know how to change the range of current hour in timepicker.

public void time(){
    tp = new TimePicker(this);
    tp.setIs24HourView(false);
    new AlertDialog.Builder(this)
    .setTitle("Set Time")
    .setView(tp)
    .setPositiveButton("Ok", new DialogInterface.OnClickListener()

    {
        public void onClick(DialogInterface dialog, int which, int hourofday,int minute) {
            // TODO Auto-generated method stub
            //Toast.makeText(getApplicationContext(), ""+dp.getMonth()+1+" "+dp.getDayOfMonth()+" "+dp.getYear(), Toast.LENGTH_LONG).show();

            String tme = tp.getCurrentHour() +":"+tp.getCurrentMinute();
            SimpleDateFormat sdf = new SimpleDateFormat("hh:mm a",Locale.US);


                et1.setText(sdf);





        }

I want to change it to 12-hour format

1

There are 1 best solutions below

0
On

Instead of using an AlertDialog I believe you might want to use a TimePickerDialog. There is a constructor built in to that where you can set the initial time, and whether it is the 12 or 24 hour clock. http://developer.android.com/reference/android/app/TimePickerDialog.html