- object of
java.util.Date
has attribute that holds count of seconds from 01-01-1970 01:00:00.000 - Java 8 comes with new API (should be in
java.time.*
package) inspired by Joda-Time - objects from new date/time API have attributes as
year
,month
,day
, ... with explicit value - objects of
LocalDateTime*
NOT contains zoned information - for this purpose should be usedZonedDateTime*
classes - new API provides more new methods, e.g.:
format(...)
,parse(...)
,now()
, ...
java.sql.Date#toLocalDate
, resp.java.sql.Time#toLocalTime
orjava.sql.Timestamp#toLocalDateTime
- from
java.util.Date
is possible to get object ofjava.time.Instant
and after then useLocalDateTime#ofInstant()
(Beware: it provides onlyLocalDateTime
class)
- class
java.time.Duration
- is time-based
- units granularity is nanoseconds .. days
#between()
returns HOURS by default#equal()
compares only attributesnanos
andseconds
- class
java.time.Period
- is date-based
- units granularity is days .. years
#between()
returns YEARS by default#equal()
compares only attributesyaers
,months
anddays
- class
java.time.temporal.ChronoUnit
- units granularity is nanoseconds .. forever
- it provides easy conversion to
Duration
which is internally used byChronoUnit
- see
ChronoUnit#getDuration