时区转换问题

当数据库时区是UTC,查询时日期是Date类型,Date类型是默认时区,查询时需做转换

public static Date stringToDate(String date, String format) {
        try {
            SimpleDateFormat simpleDateFormat = new SimpleDateFormat(format);
            simpleDateFormat.setTimeZone(TimeZone.getTimeZone("UTC"));//设置日期时区
            return simpleDateFormat.parse(date);
        }catch (Exception e){

        }
        return new Date();
    }

你可能感兴趣的:(JAVA)