解决MapStruct的时区问题

This commit is contained in:
shizhong
2023-08-23 12:11:47 +08:00
parent 287a17a9ff
commit eb4434ecbc
7 changed files with 22 additions and 11 deletions

View File

@ -36,6 +36,9 @@ public class DateUtils {
* @return LocalDateTime
*/
public static Date of(LocalDateTime date) {
if (date == null) {
return null;
}
// 将此日期时间与时区相结合以创建 ZonedDateTime
ZonedDateTime zonedDateTime = date.atZone(ZoneId.systemDefault());
// 本地时间线 LocalDateTime 到即时时间线 Instant 时间戳
@ -51,6 +54,9 @@ public class DateUtils {
* @return LocalDateTime
*/
public static LocalDateTime of(Date date) {
if (date == null) {
return null;
}
// 转为时间戳
Instant instant = date.toInstant();
// UTC时间(世界协调时间,UTC + 00:00)转北京(北京,UTC + 8:00)时间