Write a Java program to get the current local time


The code you provided is a Java program that uses the java.time package to get the current local time and print it to the console. Here is a breakdown of the code:

  • The java.time package is imported at the beginning of the code.
  • The Current_Time class is defined, which contains the main method.
  • Within the main method, the LocalTime.now() method is called to get the current local time and store it in the t variable.
  • The System.out.println() method is called to print the string "Current Local Time : " concatenated with the value of the t variable, which represents the current local time.

When you run this program, it will output the current local time in the following format: hh:mm:ss.nnnnnnnnn, where hh is the hour, mm is the minute, ss is the second, and nnnnnnnnn is the nanosecond.

Source Code

import java.time.*;
public class Current_Time
{
	public static void main(String[] args)
	{
		LocalTime t = LocalTime.now();
		System.out.println("Current Local Time : " + t);
	}
}

Output

Current Local Time : 13:54:17.291849

Example Programs