and time API for Java. • It is based on ISO 8601 standard. • The reference implementation is called "ThreeTen". • Specification Leads: Stephen Colebourne, Michael Nascimento Santos and Roger Riggs.
and times, using information interchange. • Based on Gregorian calendar system (1582). • JIS X 0301 is Japanese translations with remarks about Japanese chronology. • ISO 8601 and Unix time are incompatible. Unix time is basis of java.util.Date, et al.
the offset from UTC • UTC: ‘Z’ e.g. 06:30:45Z • Not UTC: +hh:mm or -hh:mm e.g. 15:30:45+09:00 (JST, Asia/Tokyo) 02:30:45-08:00 (PST, America/Los_Angeles)
month, day and week. • calendar date YYYY-MM-DD e.g. 2014-03-21 • ordinal date YYYY-DDD e.g. 2014-080 • week date YYYY-Www-D e.g. 2014-W12-5 • Short representations: • year-month YYYY-MM e.g. 2014-03 • year YYYY e.g. 2014 • century YY e.g. 20 • month-day --MM-DD e.g. --03-21
or 31 days 1 January 01~31 7 July 01~31 2 February 01~28/29 8 August 01~31 3 March 01~31 9 September 01~30 4 April 01~30 10 October 01~31 5 May 01~31 11 November 01~30 6 June 01~30 12 December 01~31
the orbital period of Earth (365.242 19 days), 12 months. • common year = 365 days • leap year = 366 days • 0000~9999 (0000~1582 is reserved) mod 4 mod 100 mod 400 year Not Zero - - common year Zero Not Zero - leap year Zero Zero Not Zero common year Zero Zero Zero leap year
1st week of year = a week contents the first Thursday of the year. • a year contents 52 or 53 weeks. 1 Monday 2 Tuesday 3 Wednesday 4 Thursday 5 Friday 6 Saturday 7 Sunday
(adopt also two times) • two dates : YYYY-MM-DD/YYYY-MM-DD e.g. 2013-12-31/2014-03-21 • start date and duration : YYYY-MM-DD/PnYnMnD e.g. 2013-12-31/P1Y3M22D • end date and duration : PnYnMnD/YYYY-MM-DD e.g. P1Y3M22D/2013-03-21 • duration : PnYnMnD e.g. P1Y3M22D
Reference Implementation: ThreeTen • Relational projects: • ThreeTen-Extra: Features dropped from JDK8, i.e. UTC/TAI full support, Coptic chronology, et al. https://github.com/ThreeTen/threeten-extra • ThreeTen-Backport: JSR 310 like API for JDK7. https://github.com/ThreeTen/threetenbp • Joda-Time: Provides many hints to JSR 310. http://www.joda.org/joda-time/
Date and Time Formatter often java.time.chrono Chronology supports partially java.time.temporal Low-level API rarely java.time.zone Low-level API rarely
Chrono. LocalDate Date N/A compatible enable LocalDateTime Date + Time N/A compatible enable LocalTime Time N/A compatible N/A OffsetDateTime Date + Time offset compatible disable OffsetTime Time offset compatible N/A ZonedDateTime Date + Time zone id extended enable
with other date/time. e.g. LocalDate today = LocalDate.of(2014, 3, 21); boolean b = today.isAfter(LocalDate.of(2014, 3, 19)); // b == true plus- minus- Add/subtract field value. e.g. LocalDate tomorrow = today.plusDays(2); // tomorrow.toString() : “2014-03-23” isLeapYear Verify a date is leap year. e.g. boolean leap = today.isLeapYear(); // leap == false
formatter. e.g. String s = today.toString(); // s : “2014-03-21” format(DateTimeFormatter f) Format using custom formatter. e.g. String s = today.format(formatter); parse(String s) Parse using default formatter. e.g. LocalDate d = LocalDate .parse(“2014-03-21”); parse(String s, DateTimeFormatter f) Parse using custom formatter. e.g. LocalDate d = LocalDate .parse(“2014-03-21”, formatter);
some local chronology (e.g., Japanese Era, Minguo Era, Thai Buddhist Era and Hijrah Era). • ChronoLocalDate and its sub-classes (incl. LocalDate) support chronology. • ChronoLocalDateTime<D>/ChronoZonedDateTime<D> instead of LocalDateTime/ZonedDateTime • dates/times that have different chronology can convert by from method each other.
a nano second. • The epoch is 1970-01-01T00:00:00Z • Convert from/to LocalDateTime, OffsetDateTime or ZonedDateTime. • Convert from/to java.util.Date, which means that Instant is the only interface to java.util.Date.
Period (JSR 310) is a period (ISO 8601) between two dates and represents as a date-scale. i.e. format as "P1Y2M3D" • Duration (JSR 310) is a period (ISO 8601) between any two temporals and represents as a time-scale. i.e. format as "PT15H30M45D" • Attention: those definitions are different from them of ISO 8601.
• There are some clocks, having relation of zones (incl. current zone), fixed clock (for testing) and custom. • By default, it uses the clock of current zone. • now method (LocalDate, et al.) creates a temporal instance from a clock. e.g. LocalDate.now(); LocalDate.now(zoneId); LocalDate.now(Clock.fixed(instant, ZoneId.systemDefault);