All Downloads are FREE. Search and download functionalities are using the official Maven repository.

io.github.kbachilo.jooq.converter.MillisToLocalDateTimeConverter Maven / Gradle / Ivy

package io.github.kbachilo.jooq.converter;

import org.jooq.Converter;

import java.time.Instant;
import java.time.LocalDateTime;
import java.time.ZoneId;
import java.time.ZonedDateTime;
import java.util.TimeZone;

public class MillisToLocalDateTimeConverter implements Converter {

    public LocalDateTime from(Long databaseObject) {
        Instant instant = Instant.ofEpochMilli(databaseObject);
        return LocalDateTime.ofInstant(instant, TimeZone.getDefault().toZoneId());
    }

    public Long to(LocalDateTime userObject) {
        ZonedDateTime zonedDateTime = userObject.atZone(ZoneId.systemDefault());
        return zonedDateTime.toInstant().toEpochMilli();
    }

    public Class fromType() {
        return Long.class;
    }

    public Class toType() {
        return LocalDateTime.class;
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy