get LocalDate From Timestamp - Java java.time

Java examples for java.time:LocalDate

Description

get LocalDate From Timestamp

Demo Code


//package com.java2s;
import java.time.Instant;
import java.time.LocalDate;
import java.time.LocalDateTime;

import java.util.TimeZone;

public class Main {
    public static LocalDate getDateFromTimestamp(long timestamp) {
        LocalDateTime date = getDateTimeFromTimestamp(timestamp);
        return date == null ? null : date.toLocalDate();
    }/*w  w  w .  ja v a 2 s  .  c  om*/

    public static LocalDateTime getDateTimeFromTimestamp(long timestamp) {
        if (timestamp == 0)
            return null;
        return LocalDateTime.ofInstant(Instant.ofEpochSecond(timestamp),
                TimeZone.getDefault().toZoneId());
    }
}

Related Tutorials