1. 程式人生 > >java中utc時間怎麼轉換為本地時間?

java中utc時間怎麼轉換為本地時間?

java utc轉本地時間的方法:
1、建立一個格式化時間物件simpleDateFormat,並初始化格式yyyy-MM-dd HH:mm:ss:
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
2、建立時區物件utcZone,獲取utc所在的時區
TimeZone utcZone = TimeZone.getTimeZone("UTC");
3、設定utc時區,為轉換做準備
simpleDateFormat.setTimeZone(utcZone);
4、獲取本地時間,並轉換
Date myDate = simpleDateFormat.parse(rawQuestion.getString("AskDateTime"));
5,按照上面的流程就轉換本地時間了。