如何根据Android中的时区选择转换时间?

Swi*_*ift 1 timezone datetime android android-studio android-timepicker

我的应用程序下载购物详细信息。
示例:伦敦时间 5:30 下载购物详细信息。
现在,更改任何其他时区,以便根据所选时区转换下载时间。
时区正在从日期/时间下的设置更改。 如何以编程方式实现这一点?那么如何根据时区选择转换下载时间

Rag*_*dra 5

尝试这个,

我假设您已在伦敦时间中午 12:00 下载购物详细信息。我使用 HH 假设您使用 24 小时格式。如果要将其转换为设备默认时区,请使用 DateFormat 设置时区并格式化现有时间。

TimeZone.getDefault()给出设备默认时区。

 try {
       DateFormat utcFormat = new SimpleDateFormat("HH:mm");
       utcFormat.setTimeZone(TimeZone.getTimeZone("GMT"));

       Date date = utcFormat.parse("12:00");

       DateFormat deviceFormat = new SimpleDateFormat("HH:mm");
       deviceFormat.setTimeZone(TimeZone.getDefault()); //Device timezone

       String convertedTime = deviceFormat.format(date);

} catch(Exception e){

}
Run Code Online (Sandbox Code Playgroud)