mirror of
https://gitee.com/chinabugotech/hutool.git
synced 2025-05-09 23:51:34 +08:00
添加转换时区的相关方法
This commit is contained in:
parent
a38aea70f6
commit
106361abd9
@ -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);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获得指定年份的总天数
|
||||
*
|
||||
|
Loading…
x
Reference in New Issue
Block a user