mirror of
https://gitee.com/dromara/hutool.git
synced 2025-05-16 21:19:35 +08:00
Merge pull request #2364 from majiang213/v5-dev-majiang
DateUtil添加转换时区的方法
This commit is contained in:
commit
8ea0f676b8
@ -18,6 +18,7 @@ import java.text.SimpleDateFormat;
|
||||
import java.time.Instant;
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.Year;
|
||||
import java.time.ZoneId;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import java.time.temporal.TemporalAccessor;
|
||||
import java.util.*;
|
||||
@ -2100,6 +2101,45 @@ public class DateUtil extends CalendarUtil {
|
||||
return LocalDateTimeUtil.of(date);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@link Date} 转换时区
|
||||
*
|
||||
* @param date {@link Date}
|
||||
* @param zoneId{@link zoneId}
|
||||
* @return {@link DateTime}
|
||||
* @see DateTime(Date,ZoneId)
|
||||
* @since 5.0.5
|
||||
*/
|
||||
public static DateTime convertTimeZone(Date date, String zoneId) {
|
||||
return new DateTime(date, ZoneUtil.toTimeZone(ZoneId.of(zoneId)));
|
||||
}
|
||||
|
||||
/**
|
||||
* {@link Date} 转换时区
|
||||
*
|
||||
* @param date {@link Date}
|
||||
* @param zoneId{@link zoneId}
|
||||
* @return {@link DateTime}
|
||||
* @see DateTime(Date, ZoneId )
|
||||
* @since 5.0.5
|
||||
*/
|
||||
public static DateTime convertTimeZone(Date date, ZoneId zoneId) {
|
||||
return new DateTime(date, ZoneUtil.toTimeZone(zoneId));
|
||||
}
|
||||
|
||||
/**
|
||||
* {@link Date} 转换时区
|
||||
*
|
||||
* @param date {@link Date}
|
||||
* @param timeZone{@link timeZone}
|
||||
* @return {@link DateTime}
|
||||
* @see DateTime(Date,ZoneId)
|
||||
* @since 5.0.5
|
||||
*/
|
||||
public static DateTime convertTimeZone(Date date, TimeZone timeZone) {
|
||||
return new DateTime(date, timeZone);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获得指定年份的总天数
|
||||
*
|
||||
|
@ -5,24 +5,11 @@ import cn.hutool.core.util.ObjectUtil;
|
||||
import cn.hutool.core.util.ReUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
|
||||
import java.time.DayOfWeek;
|
||||
import java.time.Duration;
|
||||
import java.time.Instant;
|
||||
import java.time.LocalDate;
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.LocalTime;
|
||||
import java.time.Period;
|
||||
import java.time.ZoneId;
|
||||
import java.time.ZonedDateTime;
|
||||
import java.time.*;
|
||||
import java.time.chrono.ChronoLocalDateTime;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import java.time.format.DateTimeFormatterBuilder;
|
||||
import java.time.temporal.ChronoField;
|
||||
import java.time.temporal.ChronoUnit;
|
||||
import java.time.temporal.Temporal;
|
||||
import java.time.temporal.TemporalAccessor;
|
||||
import java.time.temporal.TemporalUnit;
|
||||
import java.time.temporal.WeekFields;
|
||||
import java.time.temporal.*;
|
||||
import java.util.Date;
|
||||
import java.util.TimeZone;
|
||||
|
||||
@ -30,7 +17,7 @@ import java.util.TimeZone;
|
||||
* JDK8+中的{@link LocalDateTime} 工具类封装
|
||||
*
|
||||
* @author looly
|
||||
* @see DateUtil java7和一下版本,使用Date工具类
|
||||
* @see DateUtil java7和以下版本,使用Date工具类
|
||||
* @see DatePattern 常用格式工具类
|
||||
* @since 5.3.9
|
||||
*/
|
||||
|
Loading…
Reference in New Issue
Block a user