Use pattern letter uppercase X
for an offset that may use Z
for zero
DateTimeFormatter timeFormatter = DateTimeFormatter.ofPattern("HHmmssXXX");
OffsetTime time = OffsetTime.parse("115601Z", timeFormatter);
System.out.println(time);
Output from this snippet is:
11:56:01Z
To convert to LocalTime
just use .toLocalTime()
as you are already doing.
For pattern letter Z
give offset as +0000
Edit: As you mentioned in the comment, the opposite way to repair the situation is to keep the format pattern string and parse a string that matches the required format:
DateTimeFormatter timeFormatter = DateTimeFormatter.ofPattern("HHmmssZ");
OffsetTime time = OffsetTime.parse("115601+0000", timeFormatter);
The result is the same as before. One uppercase letter Z
in the format pattern string matches (quoting the documentation):
… the hour and minute, without a colon, such as '+0130'.
Link
Documentaion of DateTimeFormatter
and the pattern letters.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…