Offset-from-UTC
The XXX
in your formatting pattern refers to an offset-from-UTC. This means the date and time-of-day represent a moment that is a number of hours-minutes-seconds ahead of, or behind, the baseline of UTC.
OffsetDateTime
So parse that input with OffsetDateTime
.
OffsetDateTime odt = OffsetDateTime.parse( "2019-01-23T12:34:56.123+05:30" ) ;
Do not be mislead into using the LocalDateTime
class for such inputs. This class purposely lacks any concept of time zone or offset-from-UTC. So this class cannot be used to represent a moment. Parsing your inputs with this class is recklessly discarding valuable information. See: What's the difference between Instant and LocalDateTime?

DateTimeFormatter
To generate strings representing this value in standard ISO 8601 format, merely call toString
.
String output = odt.toString() ; // Generate string in standard ISO 8601 format.
To generate strings in other formats, use the DateTimeFormatter
class. You can specify a custom format, or better, let the class automatically localize for you.
To localize, specify:
FormatStyle
to determine how long or abbreviated should the string be.
Locale
to determine:
- The human language for translation of name of day, name of month, and such.
- The cultural norms deciding issues of abbreviation, capitalization, punctuation, separators, and such.
Example:
Locale l = Locale.CANADA_FRENCH ; // Or Locale.US, Locale.JAPAN, etc.
DateTimeFormatter f =
DateTimeFormatter
.ofLocalizedDateTime( FormatStyle.FULL )
.withLocale( l )
;
String output = zdt.format( f );
Search Stack Overflow for more info, as DateTimeFormatter
has already been covered many many times.
ISO 8601
Your input strings happen to be in standard ISO 8601 format.
The java.time classes use these standard formats by default when parsing/generating strings. So no need to specify a formatting pattern.
About java.time
The java.time framework is built into Java 8 and later. These classes supplant the troublesome old legacy date-time classes such as java.util.Date
, Calendar
, & SimpleDateFormat
.
To learn more, see the Oracle Tutorial. And search Stack Overflow for many examples and explanations. Specification is JSR 310.
The Joda-Time project, now in maintenance mode, advises migration to the java.time classes.
You may exchange java.time objects directly with your database. Use a JDBC driver compliant with JDBC 4.2 or later. No need for strings, no need for java.sql.*
classes.
Where to obtain the java.time classes?
The ThreeTen-Extra project extends java.time with additional classes. This project is a proving ground for possible future additions to java.time. You may find some useful classes here such as Interval
, YearWeek
, YearQuarter
, and more.