-
Disponible depuis les premières versions de Java
-
Très déconseillée
The class Date
represents a specific instant in time, with millisecond precision.
Date date = new Date();
int hours = date.getHours();
date.setHours(hours + 1);
La classe confond la notion d’instant, et la mesure de cet instant dans un référentiel spécifique (p.e. le calendrier grégorien)
TheCalendar
class is an abstract class that provides methods for converting between a specific instant in time and a set of calendar fields such asYEAR
,MONTH
,DAY_OF_MONTH
,HOUR
, and so on, and for manipulating the calendar fields, such as getting the date of the next week.
Calendar now = Calendar.getInstance();
int hours = now.get(Calendar.HOUR_OF_DAY);
now.set(Calendar.HOUR_OF_DAY, 1);
now.add(Calendar.HOUR_OF_DAY, 1);
now.roll(Calendar.HOUR_OF_DAY, 1);
-
Corrige les problèmes de
Date
et deCalendar
-
Disponible depuis Java 8 dans le JDK
-
Directement inspiré de la librairie Joda Time
An instantaneous point on the time-line.
A time-based amount of time, such as '34.5 seconds'.
— JavaDocs
http://bit.ly/j-t-Duration
http://bit.ly/j-t-Duration
A date-based amount of time in the ISO-8601 calendar system, such as '2 years, 3 months and 4 days'.
— JavaDocs
http://bit.ly/j-t-Period
http://bit.ly/j-t-Period
|
A date without a time-zone in the ISO-8601 calendar system, such as |
|
A time without a time-zone in the ISO-8601 calendar system, such as |
|
A date-time without a time-zone in the ISO-8601 calendar system, such as |
LocalDate now = LocalDate.now();
LocalDate christmasThisYear =
LocalDate.of(now.getYear(), 12, 25);
LocalDate now = LocalDate.now();
LocalDate thirdMondayFromNowOn = now
.with(TemporalAdjusters.next(DayOfWeek.MONDAY))
.with(TemporalAdjusters.next(DayOfWeek.MONDAY))
.with(TemporalAdjusters.next(DayOfWeek.MONDAY));