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
🌐
Baeldung
baeldung.com › home › java › java dates › guide to datetimeformatter
Guide to DateTimeFormatter | Baeldung
March 26, 2025 - We can use DateTimeFormatter to uniformly format dates and times in an app with predefined or user-defined patterns. A quick and practical guide on transitioning to Java 8's new DateTime API.
🌐
How to do in Java
howtodoinjava.com › home › java date time › java datetimeformatter (with examples)
Java DateTimeFormatter (with Examples)
June 11, 2024 - DateTimeFormatter customFormatter = DateTimeFormatter.ofLocalizedDateTime( FormatStyle.LONG ); We can supply a custom pattern built with pattern characters such as ‘uuuu-MMM-dd‘ and use ofPattern() method to create a new instance.
🌐
Microsoft Learn
learn.microsoft.com › en-us › dotnet › api › java.time.format.datetimeformatter.ofpattern
DateTimeFormatter.OfPattern Method (Java.Time.Format) | Microsoft Learn
Creates a formatter using the specified pattern and locale. [Android.Runtime.Register("ofPattern", "(Ljava/lang/String;Ljava/util/Locale;)Ljava/time/format/DateTimeFormatter;", "", ApiSince=26)] public static Java.Time.Format.DateTimeFormatter?
🌐
Dariawan
dariawan.com › tutorials › java › java-datetimeformatter-tutorial-examples
Java DateTimeFormatter Tutorial with Examples | Dariawan
import java.time.LocalDate; import java.time.LocalDateTime; import java.time.LocalTime; import java.time.OffsetDateTime; import java.time.OffsetTime; import java.time.ZonedDateTime; import java.time.format.DateTimeFormatter; public class DateTimeFormatterFormatExample { static void print(String type, String result) { System.out.printf("%s: %s\n", type, result); } public static void main(String[] args) { // LocalDate DateTimeFormatter formatter1 = DateTimeFormatter.ofPattern("dd MMM yyyy"); print("LocalDate", formatter1.format(LocalDate.now())); // LocalDateTime DateTimeFormatter formatter2 = D
🌐
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 - DateTimeFormatter is a class in the java.time.format package that helps in parsing and formatting date-time objects (LocalDate, LocalTime, LocalDateTime, ZonedDateTime, etc.).
🌐
OpenJDK
cr.openjdk.org › ~rriggs › threeten › javadoc-raw-types-163 › java › time › format › DateTimeFormatter.html
DateTimeFormatter (ThreeTen Date and Time API)
Patterns are based on a simple sequence of letters and symbols. 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 ...
Find elsewhere
🌐
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 - As this formatter has an optional element, it may be necessary to parse using parseBest(java.lang.CharSequence, java.time.temporal.TemporalQuery<?>...). The returned formatter has a chronology of ISO set to ensure dates in other calendar systems are correctly converted. It has no override zone and uses the STRICT resolver style. public static final DateTimeFormatter RFC_1123_DATE_TIME
🌐
Android Developers
developer.android.com › api reference › datetimeformatter
DateTimeFormatter | API reference | Android Developers
Skip to main content · English · Deutsch · Español – América Latina · Français · Indonesia · Polski · Português – Brasil · Tiếng Việt · 中文 – 简体
🌐
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 ... DateTimeFormatter.ofPattern(pattern)); return (int) formatted.atZone(ZoneId.systemDefault()).toInstant().getEpochSecond(); } ... /** * format date to string * * @param date date instance * @param pattern date format pattern * @return return string date */ public static String toString(Date date, String pattern) { Instant instant = new java.util.Date...
🌐
BeginnersBook
beginnersbook.com › 2017 › 11 › java-datetimeformatter
Java DateTimeFormatter
import java.time.LocalDateTime; import java.time.format.DateTimeFormatter; public class Example { public static void main(String[] args) { LocalDateTime currentDateTime = LocalDateTime.now(); DateTimeFormatter format1 = DateTimeFormatter.ofPattern("dd/MM/yyyy hh:mm a"); String formatDateTime = currentDateTime.format(format1); System.out.println(formatDateTime); DateTimeFormatter format2 = DateTimeFormatter.ofPattern("dd-MM-yyyy HH:mm:ss"); String formatDateTime2 = currentDateTime.format(format2); System.out.println(formatDateTime2); } }
🌐
Microsoft Learn
learn.microsoft.com › en-us › dotnet › api › java.time.format.datetimeformatter
DateTimeFormatter Class (Java.Time.Format) | Microsoft Learn
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&nbsp;Dec&nbsp;2011'.
🌐
GeeksforGeeks
geeksforgeeks.org › java › java-time-format-datetimeformatterbuilder-class-in-java
java.time.format.DateTimeFormatterBuilder Class in Java - GeeksforGeeks
July 23, 2025 - // Java Program to illustrate DateTimeFormatterBuilder Class // Importing required classes import java.io.*; import java.lang.*; import java.time.LocalDate; import java.time.LocalDateTime; import java.time.format.DateTimeFormatter; import java.time.format.DateTimeFormatterBuilder; import java.time.format.TextStyle; import java.time.temporal.ChronoField; import java.util.Locale; // Main class // DateTimeFormatterBuilderExample class GFG { // Main driver method public static void main(String[] args) { // Creating object of LocalDate class // inside main() method LocalDate date = LocalDate.of(2021, 6, 30); // Creating object of DateTimeFormatter class // Object 1 DateTimeFormatter formatter = DateTimeFormatter.ofPattern("dd/MM/yyyy"); // Object 2 DateTimeFormatter italianFormatter = DateTimeFormatter.ofPattern("d.
🌐
ConcretePage
concretepage.com › java › java-8 › java-datetimeformatter
Java DateTimeFormatter
DateTimeFormatter dtf = DateTimeFormatter.ofPattern("yyyy-MMM-dd HH:mm:ss"); LocalDateTime ldt = LocalDateTime.parse("2018-Dec-20 08:25:30", dtf); System.out.println(ldt); Output ...
🌐
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
The rest of the process is the same as the earlier example, you pass this pattern to the static factory method ofPattern(), which returns a corresponding DateTimeFormatter instance, which is used by LocalDateTime to convert ...