更改 TimePickerDialog 以显示特定国家/地区的时间
Change TimePickerDialog to show time of specific country
我有一个 "TimePickerDialog",我想用特定国家/地区的当前时间打开那个时间选择器。请分享您的建议。
希望它能解决您的问题。我添加了一个 GMT 列表列表。希望它会有所帮助:) 它是非常直接的解决方案,但请随时提出任何问题。
//---------- 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();
我有一个 "TimePickerDialog",我想用特定国家/地区的当前时间打开那个时间选择器。请分享您的建议。
希望它能解决您的问题。我添加了一个 GMT 列表列表。希望它会有所帮助:) 它是非常直接的解决方案,但请随时提出任何问题。
//---------- 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();