com.cloud.platform.web.dozeConverter.DateToLocalDateTimeConverter Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of cloud-web-spring-boot-starter Show documentation
Show all versions of cloud-web-spring-boot-starter Show documentation
project for cloud-web-spring-boot-starter
The newest version!
package com.cloud.platform.web.dozeConverter;
import com.github.dozermapper.core.DozerConverter;
import java.time.Instant;
import java.time.LocalDateTime;
import java.time.ZoneId;
import java.util.Date;
/**
* @description:
* @author: zhou shuai
* @date: 2022/4/2 18:42
* @version: v1
*/
public class DateToLocalDateTimeConverter extends DozerConverter {
public DateToLocalDateTimeConverter() {
super(Date.class, LocalDateTime.class);
}
public LocalDateTime convertTo(Date source, LocalDateTime target) {
Instant instant = source.toInstant();
ZoneId zone = ZoneId.systemDefault();
return LocalDateTime.ofInstant(instant, zone);
}
public Date convertFrom(LocalDateTime source, Date target) {
ZoneId zone = ZoneId.systemDefault();
Instant instant = source.atZone(zone).toInstant();
return Date.from(instant);
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy