Write a Java program to get current timestamp


This Java program uses the Instant class from the java.time package to get the current timestamp. The Instant.now() method is used to obtain the current timestamp in UTC timezone. The timestamp is then printed to the console using System.out.println().

Source Code

import java.time.*;
class Current_TimeStamp
{
	public static void main(String[] args)
	{
		Instant ts = Instant.now(); 
		System.out.println("Current Timestamp : " + ts); 
	}
}

Output

Current Timestamp : 2022-11-05T08:04:34.089747900Z

Example Programs