Getting current date and time with Clock

java.time.Clock provides access to the current instant, date and time using a time-zone.

Getting current date and time with Clock

The example uses java.time.Clock to get the current date-time.
import java.time.Clock;
import java.time.Instant;

public class JavaCurrentDateTimeClock {

    public static void main(String[] args) {

        Clock clock = Clock.systemDefaultZone();

        Instant now = clock.instant();
The Clock.systemDefaultZone() method obtains a clock that returns the current instant using the best available system clock, converting to date and time using the default time-zone.
Clock clock = Clock.systemDefaultZone();

Free Spring Boot Tutorial - 5 Hours Full Course

Watch this course on YouTube at Spring Boot Tutorial | Fee 5 Hours Full Course