tl;dr
java.time.OffsetDateTime.parse( "2019-02-21T09:47:58.699004+00:00" )
java.time
What class is DateTime
? If you are using Joda-Time, know that the Joda-Time project is now in maintenance-mode. Its creator, Stephen Colbourne, went on to lead JSR 310 and implement the java.time classes built into Java.
No need for formatting pattern
Your input string is in standard ISO 8601 format. The java.time classes use the ISO 8601 formats by default when parsing/generating strings.
String input = "2019-02-21T09:47:58.699004+00:00" ; // Standard ISO 8601 format.
OffsetDateTime
Your input string indicates an offset-from-UTC but not a time zone. So the appropriate class to represent this value is OffsetDateTime
.
OffsetDateTime odt = OffsetDateTime.parse( input ) ;
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.