Plex/src/main/java/dev/plex/util/adapter/LocalDateTimeSerializer.java
2022-02-06 21:06:55 -08:00

23 lines
716 B
Java

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;
import java.time.Instant;
import java.time.LocalDateTime;
import java.time.ZoneId;
import java.time.ZoneOffset;
import java.time.format.DateTimeFormatter;
public class LocalDateTimeSerializer implements JsonSerializer<LocalDateTime>
{
@Override
public JsonElement serialize(LocalDateTime src, Type typeOfSrc, JsonSerializationContext context)
{
return new JsonPrimitive(src.toInstant(ZoneId.systemDefault().getRules().getOffset(Instant.now())).toEpochMilli());
}
}