0

I have a "TimePickerDialog", i want open that time picker with the current time of a specific country. Please share your suggestions.

Addy
  • 75
  • 2
  • 10

1 Answers1

0

hope it solve your issues. I added a list of GMT list. hope it will help:) its pretty straight forward solution but feel free to ask anything.

    //---------- Print time zone of Canada - Toronto -------------
    // for more GMT offset list :
    // https://greenwichmeantime.com

    java.util.TimeZone tz = java.util.TimeZone.getTimeZone("GMT-5");
    Calendar c = Calendar.getInstance(tz);

    System.out.println(c.get(java.util.Calendar.HOUR_OF_DAY)+":"+c.get(java.util.Calendar.MINUTE)+":"+c.get(java.util.Calendar.SECOND));
    SimpleDateFormat sdf = new SimpleDateFormat("hh:ss");


    TimePickerDialog picker = new TimePickerDialog(this, new TimePickerDialog.OnTimeSetListener() {
        @Override
        public void onTimeSet(TimePicker view, int hourOfDay, int minute) {
            // do what ever you would like to do :)
        }
    },c.get(Calendar.HOUR_OF_DAY),c.get(Calendar.MINUTE),true);

    picker.show();
Ben
  • 144
  • 2
  • 9