Avoid java.util.Date
Two other answers are correct, except that the java.util.Date class is deprecated from the new java.time ( Tutorial ) package in Java 8. The old java.util.Date/.Calendar classes are known to be unpleasant, confusing, and erroneous . Avoid them.
java.time
Get the current moment in java.time.
ZonedDateTime instantiated = ZonedDateTime.now();
UTC
As a rule, itβs better to get used to doing your internal work (business logic, database, storage) in the UTC time zone. The code above implicitly refers to the current default time zone of the JVM.
To get the current moment in UTC in java.time.
ZonedDateTime instantiated = ZonedDateTime.now( ZoneOffset.UTC );
source share