It should be

DateTimeFormatter f = DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ss.SSSXXX");

//or

DateTimeFormatter f = DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ss.SSSz");

instead of

DateTimeFormatter f = DateTimeFormatter.ofPattern("yyyy-MM-ddTHH:mm:ss.SSSZ");

From JAVADoc:

Offset X and x: This formats the offset based on the number of pattern letters. One letter outputs just the hour, such as '+01', unless the minute is non-zero in which case the minute is also output, such as '+0130'. Two letters outputs the hour and minute, without a colon, such as '+0130'. Three letters outputs the hour and minute, with a colon, such as '+01:30'. Four letters outputs the hour and minute and optional second, without a colon, such as '+013015'. Five letters outputs the hour and minute and optional second, with a colon, such as '+01:30:15'. Six or more letters throws IllegalArgumentException. Pattern letter 'X' (upper case) will output 'Z' when the offset to be output would be zero, whereas pattern letter 'x' (lower case) will output '+00', '+0000', or '+00:00'.

Answer from ninja.coder on Stack Overflow
🌐
Oracle
docs.oracle.com › en › java › javase › 22 › docs › api › java.base › java › time › format › DateTimeFormatter.html
DateTimeFormatter (Java SE 22 & JDK 22)
July 16, 2024 - A pattern is used to create a Formatter using the ofPattern(String) and ofPattern(String, Locale) methods. For example, "d MMM uuuu" will format 2011-12-03 as '3 Dec 2011'. A formatter created from a pattern can be used as many times as necessary, it is immutable and is thread-safe.
🌐
Oracle
docs.oracle.com › javase › 8 › docs › api › java › time › format › DateTimeFormatter.html
DateTimeFormatter (Java Platform SE 8 )
October 20, 2025 - A pattern is used to create a Formatter using the ofPattern(String) and ofPattern(String, Locale) methods. For example, "d MMM uuuu" will format 2011-12-03 as '3 Dec 2011'. A formatter created from a pattern can be used as many times as necessary, it is immutable and is thread-safe.
🌐
Baeldung
baeldung.com › home › java › java dates › guide to datetimeformatter
Guide to DateTimeFormatter | Baeldung
March 26, 2025 - In our example, it would be “July.” A five-letter pattern, “MMMMM,” will make the formatter use the “narrow form.” In our case, “J” would be used. Likewise, custom formatting patterns can also be used to parse a String that holds ...
🌐
Dariawan
dariawan.com › tutorials › java › java-datetimeformatter-tutorial-examples
Java DateTimeFormatter Tutorial with Examples | Dariawan
DateTimeFormatter fmt = DateTimeFormatter.ofPattern("dd-MM-yyyy HH:mm:ss.SSSZ"); ZonedDateTime zdt = ZonedDateTime.from(fmt.parse("25-12-2018 18:20:45.345+0800")); System.out.println(zdt);
🌐
How to do in Java
howtodoinjava.com › home › java date time › java datetimeformatter (with examples)
Java DateTimeFormatter (with Examples)
June 11, 2024 - // Creating a DateTimeFormatter for date time information including timezone public static final DateTimeFormatter ZDT_FORMATTER = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss a z"); //Formatting String formettedOutput = ZDT_FORMATTER.format( ...
🌐
Oracle
docs.oracle.com › en › java › javase › 17 › docs › api › java.base › java › time › format › DateTimeFormatter.html
DateTimeFormatter (Java SE 17 & JDK 17)
January 20, 2026 - A pattern is used to create a Formatter using the ofPattern(String) and ofPattern(String, Locale) methods. For example, "d MMM uuuu" will format 2011-12-03 as '3 Dec 2011'. A formatter created from a pattern can be used as many times as necessary, it is immutable and is thread-safe.
🌐
Medium
medium.com › @medcherrou › a-comprehensive-guide-to-date-and-time-formatting-in-java-with-datetimeformatter-fefb8e48ce9f
A Comprehensive Guide to Date and Time Formatting in Java with DateTimeFormatter | by Med Cherrou | Medium
December 13, 2024 - Example: DateTimeFormatter monthFormatter = DateTimeFormatter.ofPattern("MMMM"); System.out.println(LocalDate.now().format(monthFormatter)); // January · d: Day of the month without leading zero (1–9). dd: Day of the month with leading zero ...
🌐
Java67
java67.com › 2019 › 01 › 10-examples-of-format-and-parse-dates-in-java.html
10 Examples to DateTimeFormatter in Java 8 to Parse, Format LocalDate and LocalTime | Java67
June 16, 2016 - In this example, we are creating a custom DateTimeFormatter pattern to show dates in an Indian date format, like dd-MM-yyyy (16-06-2016). This is also the British date format, popular in England and some parts of the UK.
Find elsewhere
🌐
ThreeTen
threeten.org › threetenbp › apidocs › org › threeten › bp › format › DateTimeFormatter.html
DateTimeFormatter (ThreeTen backport 1.7.3-SNAPSHOT API)
public static DateTimeFormatter ofPattern​(String pattern) Creates a formatter using the specified pattern. This method will create a formatter based on a simple pattern of letters and symbols. For example, d MMM yyyy will format 2011-12-03 as '3 Dec 2011'.
🌐
Java Tips
javatips.net › api › java.time.format.datetimeformatter.ofpattern
Java Examples for java.time.format.DateTimeFormatter.ofPattern
Example 1 · @Test public void subtract_minutes_from_date_in_java8() { LocalDateTime newYearsDay = LocalDateTime.of(2013, Month.JANUARY, 1, 0, 0); LocalDateTime newYearsEve = newYearsDay.minusMinutes(1); java.time.format.DateTimeFormatter formatter = java.time.format.DateTimeFormatter.ofPattern("MM/dd/yyyy HH:mm:ss S"); logger.info(newYearsDay.format(formatter)); logger.info(newYearsEve.format(formatter)); assertTrue(newYearsEve.isBefore(newYearsDay)); } Example 2 ·
🌐
Tabnine
tabnine.com › home page › code › java › java.time.format.datetimeformatter
java.time.format.DateTimeFormatter.ofPattern java code examples | Tabnine
/** * format string time to unix time * * @param time string date * @param pattern date format pattern * @return return unix time */ public static int toUnix(String time, String pattern) { LocalDateTime formatted = LocalDateTime.parse(time, DateTimeFormatter.ofPattern(pattern)); return (int) formatted.atZone(ZoneId.systemDefault()).toInstant().getEpochSecond(); }
🌐
Oracle
docs.oracle.com › en › java › javase › 21 › docs › api › java.base › java › time › format › DateTimeFormatter.html
DateTimeFormatter (Java SE 21 & JDK 21)
January 20, 2026 - A pattern is used to create a Formatter using the ofPattern(String) and ofPattern(String, Locale) methods. For example, "d MMM uuuu" will format 2011-12-03 as '3 Dec 2011'. A formatter created from a pattern can be used as many times as necessary, it is immutable and is thread-safe.
🌐
Oracle
docs.oracle.com › javase › 10 › docs › api › java › time › format › DateTimeFormatter.html
DateTimeFormatter (Java SE 10 & JDK 10 )
A pattern is used to create a Formatter using the ofPattern(String) and ofPattern(String, Locale) methods. For example, "d MMM uuuu" will format 2011-12-03 as '3 Dec 2011'. A formatter created from a pattern can be used as many times as necessary, it is immutable and is thread-safe.
🌐
Js-joda
js-joda.github.io › js-joda › class › packages › core › src › format › DateTimeFormatter.js~DateTimeFormatter.html
DateTimeFormatter | js-joda
The returned formatter will use the default locale, but this can be changed using DateTimeFormatter.withLocale. All letters 'A' to 'Z' and 'a' to 'z' are reserved as pattern letters. The following pattern letters are defined: |Symbol |Meaning |Presentation |Examples |--------|----------------------------|------------------|---------------------------------------------------- | G | era | number/text | 1; 01; AD; Anno Domini | u | year | year | 2004; 04 | y | year-of-era | year | 2004; 04 | D | day-of-year | number | 189 | M | month-of-year | number/text | 7; 07; Jul; July; J | d | day-of-month
🌐
Microsoft Learn
learn.microsoft.com › en-us › dotnet › api › java.time.format.datetimeformatter.ofpattern
DateTimeFormatter.OfPattern Method (Java.Time.Format) | Microsoft Learn
This method will create a formatter based on a simple pattern of letters and symbols as described in the class documentation. For example, d MMM uuuu will format 2011-12-03 as '3 Dec 2011'.
🌐
Microsoft Learn
learn.microsoft.com › en-us › dotnet › api › java.time.format.datetimeformatter
DateTimeFormatter Class (Java.Time.Format) | Microsoft Learn
For example, "d MMM uuuu" will format 2011-12-03 as '3 Dec 2011'. A formatter created from a pattern can be used as many times as necessary, it is immutable and is thread-safe.
🌐
OpenJDK
cr.openjdk.org › ~rriggs › threeten › javadoc-raw-types-163 › java › time › format › DateTimeFormatter.html
DateTimeFormatter (ThreeTen Date and Time API)
A pattern is used to create a Formatter using the ofPattern(String) and ofPattern(String, Locale) methods. For example, "d MMM uuuu" will format 2011-12-03 as '3 Dec 2011'. A formatter created from a pattern can be used as many times as necessary, it is immutable and is thread-safe.