How to Convert Timestamp to Date in Java 8 or Above

We can make use of Timestamp and LocalDate classes to convert timestamp to date using the toLocalDate() method.

Example:

package org.code2care.examples;

import java.sql.Timestamp;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.time.LocalDate;
import java.util.Date;

/**
 * Convert Date format from yyyy-MM-dd
 * to dd/MM/yyyy example
 * <p>
 * author: Code2care.org
 */
public class Example {

    public static void main(String... args) {

        Timestamp timestamp = Timestamp.valueOf("2023-10-17 15:20:41");
        LocalDate localDate = timestamp.toLocalDateTime().toLocalDate();

        System.out.println("Timestamp: "+ timestamp);
        System.out.println("LocalDate: " + localDate);

    }

}

Output:

Convert Timestamp to date Java example

Comments & Discussion

Facing issues? Have questions? Post them here! We're happy to help!