TL; DR
OffsetDateTime.parse( "2010-12-27T10:50:44.000-08:00" )
ISO 8601
The input string format is defined in ISO 8601 , a family of date and time formats.
Avoid Old Time Classes
Questions and other answers use old deprecated time classes associated with the earliest versions of Java. Avoid them. Now superseded by java.time classes.
Using java.time
Your input line ends with offset-from-UTC . So, we analyze as an object OffsetDateTime .
The java.time classes use ISO 8601 formats by default when parsing / generating strings. Therefore, there is no need to specify a formatting pattern.
OffsetDateTime odt = OffsetDateTime.parse( "2010-12-27T10:50:44.000-08:00" );
If you want to view this date and time in the UTC timeline, retrieve Instant .
Instant instant = odt.toInstant();
A time zone is an offset plus a set of rules for handling anomalies, such as Daylight Saving Time (DST). If you have a time zone, use ZoneId to get the ZonedDateTime object. At the same time on the timeline, but can be viewed after another time of the wall clock .
ZoneId z = ZoneId.of( "America/Montreal" ); ZonedDateTime zdt = odt.atZoneSameInstant( z );
About java.time
The java.time framework is built into Java 8 and later. These classes supersede the nasty old legacy time classes such as java.util.Date , Calendar and SimpleDateFormat .
The Joda-Time project, now in maintenance mode , we recommend switching to the java.time classes.
To learn more, see the Oracle Tutorial . And search for qaru for many examples and explanations. JSR 310 specification .
You can exchange java.time objects directly with your database. Use a JDBC driver that conforms to JDBC 4.2 or later. No strings needed, no java.sql.* Classes needed.
Where to get java.time classes?
- Java SE 8 , Java SE 9 , and then
- Built in.
- Part of the standard Java API with integrated implementation.
- Java 9 adds some minor features and fixes.
- Java SE 6 and Java SE 7
- Most of the functionality of java.time has been ported to Java 6 and 7 in ThreeTen-Backport .
- Android
- Later versions of the Android package implementations of the java.time classes.
- For earlier Android, the ThreeTenABP project adapts ThreeTen-Backport (mentioned above). See How to use ThreeTenABP ....
The ThreeTen-Extra project extends java.time with additional classes. This project is a proof of possible future additions to java.time. Here you can find useful classes such as Interval , YearWeek , YearQuarter and more .