1

I am trying to parse date

final LocalDateTime dateTime = LocalDateTime.parse("2017-01-17 09:28:45", DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss'Z'"));

Im expecting LocalDateTime because this last 'Z' should not impact as it is in single quotes.

BTW following code is working

final LocalDateTime dateTime = LocalDateTime.parse("2017-01-17 09:28:45", DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"))
3
  • 3
    Can you clarify what your problem is? What do you want with that 'Z'??? Commented Sep 8, 2021 at 12:27
  • Indeed - why do you have a Z in your pattern when it's not in the value you're parsing? Commented Sep 8, 2021 at 12:51
  • If your string might end with Z, why don’t you simply remove the Z before parsing? Commented Sep 8, 2021 at 14:17

1 Answer 1

1

Im expecting LocalDateTime because this last 'Z' should not impact as it is in single quotes.

the Z can be ignored if you put it between brackets like this:

"yyyy-MM-dd HH:mm:ss['Z']"

The single quotes can not ignore but we use them to define a static parts like the Z in your case.

Note that the LocalDateTime not have zone part.

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.