3

I'm trying to parse a timestamp object from sql and am having problems, heres what I have:

 DateTimeFormatter dateDTF = DateTimeFormatter.ofLocalizedDateTime(FormatStyle.SHORT);


 String start = c.getStartTime().getValue();
 //Start: 2018-12-01 16:00:00
 System.out.println("Start: " + start);
 LocalDateTime startDatetime = LocalDateTime.parse(start, dateDTF);

As you can see in the commented code my with the value of start to trim down my working example.I'm getting the following error:

java.time.format.DateTimeParseException: Text '2018-12-01 16:00:00' could not be parsed at index 4

1 Answer 1

2

Use

DateTimeFormatter dtf = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");

Here you specify the pattern of the DateTimeFormat

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

2 Comments

I seriously hate that there's no proper wrapper for the SQL timestamp and I have to manually do this garbage. That being said thanks for the help! I'll accept it as soon as I can.
@Joe You shouldn’t fetch timestamp values as strings from your database. Depending on what your JDBC driver offers, see if you can fetch an Instant, an OffsetDateTime or a LocalDateTime. Use for example yourResultSet.getObject(6, Instant.class).

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.