-1

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?

8
  • How about the pattern yyyy-MM-dd HH:mm:ss? Commented Apr 11, 2022 at 17:30
  • i need only the time to be retrieved in the format "hh:mm:ss" cause thats the format which is accepted by the DB . Commented Apr 11, 2022 at 17:38
  • Change the pattern in the DateTimeFormatter you are using and must do the work. Commented Apr 12, 2022 at 7:39
  • @EvgeniEnchev, I already tried and it dint work . Commented Apr 12, 2022 at 8:27
  • @Shark, I tried SimpleDateFormat and it returned a string , I again converted it to java.sql.Time and tried inserting and I get DataType Mismatch error which is weird , I tried inserting directly with the values formed in the query in java code and they are inserted fine . Not sure why I am unable to insert with Java code. Commented Apr 12, 2022 at 8:30

1 Answer 1

0

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.