import java.text.DateFormat;import java.text.ParseException;import java.text.SimpleDateFormat;import java.util.*;public class LocalTimeTest { private static MapString, String timeZoneIds = Map.of(NRT, Asia/Tokyo, BKK, Asia/Bangkok, ICN, Asi
import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.*;
public class LocalTimeTest {
private static Map<String, String> timeZoneIds = Map.of("NRT", "Asia/Tokyo", "BKK", "Asia/Bangkok", "ICN", "Asia/Seoul", "HNL", "Pacific/Honolulu", "SIN", "Asia/Singapore", "TPE", "Asia/Taipei", "LAX", "America/Los_Angeles");
public static void main(String[] args) throws ParseException {
System.out.println(getLocalTime("2022-11-05T17:30:00.000Z"));
System.out.println(getLocalTime("2022-11-06T17:30:00.000Z"));
}
private static String getLocalTime(String gmtTime) throws ParseException {
final DateFormat formatter = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'");
formatter.setTimeZone(TimeZone.getTimeZone("GMT"));
final Date timezone = formatter.parse(gmtTime);
formatter.setTimeZone(TimeZone.getTimeZone(timeZoneIds.get("LAX")));
return formatter.format(timezone);
}
}
【文章原创作者:
阿里云代理商 http://www.558idc.com/aliyun.html 网络转载请说明出处】