java.time
See the ThreeTen-Backport project for a back-port of much of the java.time functionality to Java 6 and 7 (java.time is built into Java 8 and later). The API nearly matches so that when you eventually migrate to Java 8 or later, you’ll need do little more than change your import
statements.
The Joda-Time project is now in maintenance mode though actively maintained. The sponsors advise moving to the java.time classes.
ISO 8601
Replace that hyphen in the middle of your input string with a T
to comply with the standard ISO 8601 formats. These standard formats are used by default in the java.time classes for parsing and generating string representations of date-time values.
OffsetDateTime odt = OffsetDateTime.parse( "2017-01-05T04:44:43-06:00" );
Search Stack Overflow
I'm terribly sorry if this had been asked before
Yes, your questions are all duplicates. Please search Stack Overflow for existing answers to all your issues:
- backport of java.time, ThreeTen-Backport
- Parsing strings containing an offset-from-UTC, OffsetDateTime class
- exchanging date-time data with databases and Oracle in particular, JDBC 4.2 for directly exchanging java.time objects, or else calling new methods added to the old classes for converting to/from java.time to
java.sql.Timestamp
, or else on pre-Java-8 convert to Timestamp
by count-from-epoch numbers.
- Learning just how bad the old legacy date-time classes are, and you absolutely should go to the bother of adding the java.time backport library to your project.
Tip: Do not search from within Stack Overflow website. Their search engine is biased towards Questions while you want to search within Answers. Use site:stackoverflow.com
in DuckDuckGo, Google, or Bing.
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
.
The Joda-Time project, now in maintenance mode, advises migration to the java.time classes.
To learn more, see the Oracle Tutorial. And search Stack Overflow for many examples and explanations. Specification is JSR 310.
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.