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
🌐
Joda
joda.org › joda-time › apidocs › org › joda › time › format › DateTimeFormat.html
DateTimeFormat (Joda-Time 2.14.1 API)
Pattern provides a DateTimeFormatter based on a pattern string that is mostly compatible with the JDK date patterns.
🌐
Baeldung
baeldung.com › home › java › java dates › guide to datetimeformatter
Guide to DateTimeFormatter | Baeldung
March 26, 2025 - Symbol Meaning Presentation Examples ------ ------- ------------ ------- H hour-of-day (0-23) number 0 m minute-of-hour number 30 s second-of-minute number 55 S fraction-of-second fraction 978 n nano-of-second number 987654321 · It’s quite simple to use DateTimeFormatter to format a java.time.LocalTime instance.
Discussions

java - Parsing a date using DateTimeFormatter ofPattern - Stack Overflow
78 Unable to obtain ZonedDateTime from TemporalAccessor using DateTimeFormatter and ZonedDateTime in Java 8 More on stackoverflow.com
🌐 stackoverflow.com
Why Java.Time's DateTimeFormatter cannot parse fraction of second like SimpleDateFormat?
int min = 1; int max = 3; DateTimeFormatter formatter = new DateTimeFormatterBuilder() .appendPattern("yyyy-MM-dd HH:mm:ss") .appendFraction(ChronoField.MILLI_OF_SECOND, min, max, true) .toFormatter(); where min is the minimum digits expected for milliseconds and max is the maximum digits expected for milliseconds More on reddit.com
🌐 r/javahelp
5
1
September 2, 2020
Is there a thread safe JDK 8 equivalent for SimpleDateFormat?

See java.time.format package. DateTimeFormatter "is immutable and thread-safe."

More on reddit.com
🌐 r/java
11
4
May 30, 2012
SimpleDateFormat format() method throws exception with formats having single quotes in pattern
It's probably a bug.. Just to make sure, you're using com.codename1.l10n.SimpleDateFormat and not the one from the java package. Right? It's supposed to support the format characters of the JavaSE SimpleDateFormat but there are probably issues with edge cases. More on reddit.com
🌐 r/cn1
7
2
August 29, 2021
🌐
Java Guides
javaguides.net › 2024 › 06 › java-datetimeformatter.html
Java DateTimeFormatter
June 30, 2024 - DateTimeFormatter in Java, part of the java.time.format package, is used for formatting and parsing date-time objects.
🌐
Oracle
docs.oracle.com › javase › 8 › docs › api › java › time › format › DateTimeFormatter.html
DateTimeFormatter (Java Platform SE 8 )
October 20, 2025 - 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 ISO_WEEK_DATE
🌐
Dotnetcodr
dotnetcodr.com › 2017 › 09 › 30 › formatting-dates-in-java-using-datetimeformatter
Formatting dates in Java using DateTimeFormatter | Exercises in .NET with Andras Nemes
September 30, 2017 - Introduction Formatting dates - and numbers for that matter - can be a complex matter. The DateTimeFormatter class provides pre-defined formats that adhere to ISO and RCF specifications. DateTimeFormatter The following date related classes we've seen on this blog, i.e. LocalDate LocalTime LocalDateTime ZonedDateTime ...have a method called "format" which accepts a DateTimeFormatter class.
🌐
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 - If you want to learn more, you can also see the What's New in Java 8 course on Pluralsight. Japanese use a different date format than the UK and USA; they put the year first followed by month and day. You can define both long and short date formats for Japan using patterns "yyyy-MM-dd" and "yy-MM-dd" as shown in the below example · DateTimeFormatter japan = DateTimeFormatter.ofPattern("yy-MM-dd"); String japanese = now.format(japan); System.out.println("Date in Japan dateformat : " + japanese); Output Date in Japan date format: 16-06-16
Find elsewhere
🌐
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 // Using optionalStart() and optionalEnd() Methods // Importing required libraries 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.temporal.ChronoField; // Main class public class GFG { // Main driver methods public static void main(String[] args) { // Creating an object of DateTimeFormatter class DateTimeFormatter parser = new DateTimeFormatterBuilder() .appendPattern("[yyyy][yyyyM
🌐
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'.
🌐
How to do in Java
howtodoinjava.com › home › java date time › java datetimeformatter (with examples)
Java DateTimeFormatter (with Examples)
June 11, 2024 - Java examples to use DateTimeFormatter for formatting ZonedDateTime, LocalDateTime, LocalDate and LocalTime with inbuilt and custom patterns.
🌐
ConcretePage
concretepage.com › java › java-8 › java-datetimeformatter
Java DateTimeFormatter
We can fetch DateTimeFormatter object information using following methods. getChronology(): Gets chronology. getDecimalStyle(): Gets decimal style. getLocale(): Gets locale. getResolverFields(): Gets resolver fields. getResolverStyle(): Gets resolver style. getZone(): Gets zone. Find the sample example. package com.concretepage; import java.time.format.DateTimeFormatter; public class DateTimeFormatterDemo { public static void main(String[] args) { DateTimeFormatter dtf = DateTimeFormatter.ISO_LOCAL_DATE_TIME; System.out.println("Chronology: " + dtf.getChronology()); System.out.println("DecimalStyle: " + dtf.getDecimalStyle()); System.out.println("Locale: "+ dtf.getLocale()); System.out.println("ResolverFields: "+ dtf.getResolverFields()); System.out.println("ResolverStyle: "+ dtf.getResolverStyle()); System.out.println("Zone: "+ dtf.getZone()); } } Output
🌐
W3Schools
w3schools.com › java › java_date.asp
Java Date and Time
The following example will remove ...println("Before formatting: " + myDateObj); DateTimeFormatter myFormatObj = DateTimeFormatter.ofPattern("dd-MM-yyyy HH:mm:ss"); String formattedDate = myDateObj.format(myFormatObj); ...
🌐
Coderanch
coderanch.com › t › 678156 › java › DateTimeFormatter
DateTimeFormatter question [Solved] (Beginning Java forum at Coderanch)
April 6, 2017 - The Java compiler now thinks it has to look in your own class DateTimeFormatter instead of the standard class java.time.format.DateTimeFormatter. Rename your own class to something else. In your second example, which has class DateTimeFormatter2, it is still going wrong because you still have your other class DateTimeFormatter from the first example in the package chapter3.
🌐
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.).
🌐
Oracle
docs.oracle.com › javase › tutorial › datetime › iso › format.html
Parsing and Formatting (The Java™ Tutorials > Date Time > Standard Calendar)
July 21, 2013 - The following code, from the Flight example, converts an instance of ZonedDateTime using the format "MMM d yyy hh:mm a". The date is defined in the same manner as was used for the previous parsing example, but this pattern also includes the hour, minutes, and a.m.
🌐
DigitalOcean
digitalocean.com › community › tutorials › java-simpledateformat-java-date-format
Master Java Date Formatting: SimpleDateFormat & DateFormat Guide | DigitalOcean
December 20, 2024 - These classes are part of the java.text ... formatting, making it highly customizable. For example, you can specify patterns like “dd-MM-yyyy” for dates or “HH:mm:ss” for times....
🌐
OpenJDK
cr.openjdk.org › ~rriggs › threeten › javadoc-raw-types-163 › index.html
DateTimeFormatter (ThreeTen Date and Time API)
JavaScript is disabled on your browser · Frame Alert · This document is designed to be viewed using the frames feature. If you see this message, you are using a non-frame-capable web client. Link to Non-frame version
🌐
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 - 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 ISO_WEEK_DATE
🌐
Joda
joda.org › joda-time › apidocs › org › joda › time › format › DateTimeFormatter.html
DateTimeFormatter (Joda-Time 2.14.1 API)
java.lang.Object · org.joda.time.format.DateTimeFormatter · public class DateTimeFormatter extends Object · Controls the printing and parsing of a datetime to and from a string. This class is the main API for printing and parsing used by most applications.
🌐
BeginnersBook
beginnersbook.com › 2017 › 11 › java-datetimeformatter
Java DateTimeFormatter
November 1, 2017 - import java.time.LocalDateTime; import java.time.format.DateTimeFormatter; public class Example { public static void main(String[] args) { LocalDateTime datetime = LocalDateTime.now(); DateTimeFormatter dateTimeFormatter = DateTimeFormatter.BASIC_ISO_DATE; String formattedDate = dateTimeFormatter.format(datetime); System.out.println(formattedDate); DateTimeFormatter dateTimeFormatter2 = DateTimeFormatter.ISO_LOCAL_DATE; String formattedDate2 = dateTimeFormatter2.format(datetime); System.out.println(formattedDate2); DateTimeFormatter dateTimeFormatter3 = DateTimeFormatter.ISO_LOCAL_TIME; String formattedDate3 = dateTimeFormatter3.format(datetime); System.out.println(formattedDate3); DateTimeFormatter dateTimeFormatter4 = DateTimeFormatter.ISO_LOCAL_DATE_TIME; String formattedDate4 = dateTimeFormatter4.format(datetime); System.out.println(formattedDate4); } }