ChronoUnit
Description
ChronoUnit enum represents units of time.
It contains the following constants:
CENTURIES, DAYS, DECADES, ERAS, FOREVER, HALF_DAYS, HOURS, MICROS, MILLENNIA, MILLIS, MINUTES, MONTHS, NANOS, SECONDS, WEEKS, and YEARS
.
Example
The following code shows how to use ChronoUnit enum constants.
import java.time.LocalDateTime;
import java.time.temporal.ChronoUnit;
/*from w ww.j a v a2 s .c om*/
public class Main {
public static void main(String[] args) {
LocalDateTime now = LocalDateTime.now();
// Get the date time 10 days ago
LocalDateTime localDateTime1 = now.minus(10, ChronoUnit.DAYS);
System.out.println(localDateTime1);
}
}
The code above generates the following result.