Plex/src/main/java/dev/plex/util/adapter/LocalDateTimeSerializer.java

23 lines
716 B
Java
Raw Normal View History

package dev.plex.util.adapter;
import com.google.gson.JsonElement;
import com.google.gson.JsonPrimitive;
import com.google.gson.JsonSerializationContext;
import com.google.gson.JsonSerializer;
import java.lang.reflect.Type;
2022-02-07 05:06:55 +00:00
import java.time.Instant;
import java.time.LocalDateTime;
2022-02-07 05:06:55 +00:00
import java.time.ZoneId;
import java.time.ZoneOffset;
import java.time.format.DateTimeFormatter;
2022-02-07 05:06:55 +00:00
public class LocalDateTimeSerializer implements JsonSerializer<LocalDateTime>
{
@Override
public JsonElement serialize(LocalDateTime src, Type typeOfSrc, JsonSerializationContext context)
{
2022-02-07 05:06:55 +00:00
return new JsonPrimitive(src.toInstant(ZoneId.systemDefault().getRules().getOffset(Instant.now())).toEpochMilli());
}
}