TL;DR
ZonedDateTime zdt = LocalDateTime.parse( "2014-02-15 05:18:08".replace( " " , "T" ) ).atOffset( ZoneOffset.UTC ).atZoneSameInstant( ZoneId.of( "Asia/Kolkata" ) ) ;
LocalDate ld = zdt.toLocalDate();
LocalTime lt = zdt.toLocalTime();
,
, .
JDBC 4.2 java.time- .
Instant instant = Instant.now() ;
myPreparedStatement.setObject( … , instant ) ;
.
Instant instant = myResultSet.getObject( … , Instant.class ) ;
java.time
java.time Java 8 , Joda -Time-.
java.sql.Timestamp Instant.java.sql.Date LocalDate.java.sql.Time LocalTime.
-
Parsing
, java.time. , Java. , .
ISO 8601. SPACE T.
String input = "2014-02-15 05:18:08".replace( " " , "T" ) ;
LocalDateTime
LocalDateTime, - offset-from-UTC .
LocalDateTime ldt = LocalDateTime.parse( input ) ;
OffsetDateTime
, String UTC . UTC.
OffsetDateTime odt = ldt.atOffset( ZoneOffset.UTC ) ;
ZonedDateTime
, , UTC.
atZoneSameInstant , ZonedDateTime , OffsetDateTime. , .
ZoneId z = ZoneId.of( "Asia/Kolkata" );
ZonedDateTime zdt = odt.atZoneSameInstant( z );
LocalDate LocalTime
, Local….
LocalDate ld = zdt.toLocalDate();
LocalTime lt = zdt.toLocalTime();
toString , ISO 8601. , DateTimeFormatter. .
- . Locale , , ..
Locale locale = new Locale( "en" , "IN" );
DateTimeFormatter f = DateTimeFormatter.ofLocalizedDateTime( FormatStyle.SHORT ).withLocale( locale );
String output = zdt.format( f );
java.time
java.time Java 8 . legacy -, java.util.Date, Calendar SimpleDateFormat.
Joda-Time, , java.time.
, . Oracle. Qaru . JSR 310.
java.time . JDBC, JDBC 4.2 , , java.sql.*.
java.time?
The ThreeTen-Extra project extends java.time with additional classes. This project is proof of possible future additions to java.time. Here you can find useful classes, such as Interval, YearWeek, YearQuarterand longer .