How to retrieve time in hh:mm:ss format from Time stamp in Java

1.6k Views Asked by At

I have an issue related to retrieving time from time stamp. Below is the code, I get the timestamp from gui, which I need to convert into hh:mm:ss and insert into database.

LocalDate timestamp = LocalDate.parse(getOfferingLetter().getCreatedTimeStamp(),DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss.SSSSSS"));
Timestamp.valueOf(timestamp.atStartOfDay(); 

The above code retrieves date like this 2022-04-08 00:00:00.0. I need the time to be retrieved like this 00:00:00, how do I do this without using SimpleDateFormat?

1

There are 1 best solutions below

0
On

Well, this will give you the time:

LocalDateTime localDateTime = LocalDateTime.parse("2000-10-10 10:15:33.123456", DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss.SSSSSS"));
String timeHHmmss = localDateTime.format(DateTimeFormatter.ofPattern("HH:mm:ss"));
LocalTime localTime = LocalTime.parse(timeHHmmss);

But you cannot create Timestamp from LocalTime.