最近用到冬令时与夏令时,与其他时区转换,现做一下整理
1.转换指定时区的默认时间
/**
* 转换指定时区的默认时间格式
* @param utcTime
* @param tz
* @param locale
* @return
*/
public static String toZoneDateTimeByDefaultFormat(Timestamp utcTime, TimeZone tz, Locale locale) {
DateFormat df = DateFormat.getDateTimeInstance(DateFormat.MEDIUM, DateFormat.MEDIUM, locale);
df.setTimeZone(tz);
return df.format(utcTime);
}
public static void main(String[] args) {
Timestamp utcTime = Timestamp.valueOf("2019-10-11 11:52:36");
TimeZone tz = TimeZone.getTimeZone("Europe/London");
String byDefaultFormat = DateUtil.toZoneDateTimeByDefaultFormat(utcTime , tz , Locale.getDefault());
System.out.println(byDefaultFormat);
}