[英]change time from Time picker by Location in android
我使用此代碼,但在其他時區無法正常工作。 通過更改時區或當前系統時區如何更改此時間
整數小時 分鍾
Calendar cal = Calendar.getInstance();
cal.set(Calendar.HOUR, 16);
cal.set(Calendar.MINUTE, 30);
cal.set(Calendar.SECOND, 0);
cal.set(Calendar.AM_PM, Calendar.PM);
TimePicker asarTime=(TimePicker)findViewById(R.id.asarTime);
asarTime.setCurrentHour(16);
asarTime.setCurrentMinute(30);
Date currentLocalTime = cal.getTime();
SimpleDateFormat date = new SimpleDateFormat("HH:mm:ss z");
date.setTimeZone(TimeZone.getTimeZone("UTC"));
String localTime = date.format(currentLocalTime);
TextView timeShow=(TextView)findViewById(R.id.textView1);
timeShow.setText(currentLocalTime.toString());
首先,按以下方式設置時區:
TimeZone tz = cal.getTimeZone();
date.setTimeZone(tz);
您可以添加檢查時區的服務以更新您的應用程序。 實際上,這種情況很少發生,用戶在使用應用程序時必須更改時區,因此您可以在每次應用程序啟動時進行檢查。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.