Java 冬令时-夏令时转换方法

最近用到冬令时与夏令时,与其他时区转换,现做一下整理

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);
    }

猜你喜欢

转载自blog.csdn.net/superiorpengFight/article/details/102912594