There are certain methods available to fetch the date and time in Java. The methods to get a date and time are using the Date class and the get() method of the Calendar class. Other than that the instant now() method also prints the current date and time in Java without any hassle.
This article will demonstrate in detail how to fetch the current date and time using the instant now() method in Java.
How to Get/Fetch Current Date and Time Using Java Instant now() Method?
The method to get the existing instant from the system clock in Java is acquired through the now() method. The instant class in Java represents a specific time instant on the current time. There are two parameters in the Java instant class that are listed below:
- Instant now() uses the UTC clock to get the current instant.
- Instant now(Clock clock) uses the specified clock as a parameter and returns the current instant.
The code implementation is depicted below:
Method 1: Instant now() Implementation
The now() is a built-in Java function that retrieves the present/current data and time instant:
//import time class from instant method
import java.time.*;
//create class
public class instantclass {
public static void main(String[] args)
{
Instant currenttime= Instant.now();
//print the results of current time
System.out.println("The current date and time Instant is : " + currenttime);
}
}
In the code above:
- A class is created to declare the functions.
- The instant now() method has been declared.
- The println() function has printed the output.
Output

The above output shows the current time and date instant.
Method 2: Getting Current DateTime in UTC
In the below-mentioned code, the Instant.now() function is used alongside the Clock.systemUTC() function to fetch the current date and time in UTC format:
import java.time.*;
public class currentclass {
public static void main(String[] args)
{
//Declare the clock as UTC
Clock dateandtime = Clock.systemUTC();
Instant p= Instant.now(dateandtime);
System.out.println("the current date and time instant is : "+ p);
}
}
In the code above :
- A class has been created to get the current date and time.
- The clock.systemUTC() method declares a clock of UTC time zone.
- The println() function returns the respective date and time instant with respect to that time zone.
Output

The above output displays the date and time instant currently.
Conclusion
There are certain methods available to fetch the current time and date. One of the useful methods is instant now() which retrieves the current time and date accordingly. The other method uses the standard clock according to the specified time zone to get the current date and time. This article has demonstrated effectively both methods in detail.