Write a Java program to get the information of a given time


This program demonstrates how to get information about the current time in Java using the LocalTime class. The LocalTime class is part of the java.time package in Java 8 and provides a way to work with time values without any date component.

In this program, the time is set to 11:54:28 using the LocalTime.of() method. Then, the getHour(),getMinute(), and getSecond() methods are called on the LocalTime object to retrieve the current hour, minute, and second respectively. Finally, the results are printed using the println() method.

Source Code

import java.time.*;
public class Get_Information_Time
{
	public static void main(String[] args)
	{	
		LocalTime t = LocalTime.of(11, 54, 28);  
		int h = t.getHour(); 
		int m = t.getMinute();  
		int s = t.getSecond(); 
		System.out.println("Current Time : " + t);
		System.out.println("Hour : " + h);
		System.out.println("Minute : " + m); 
		System.out.println("Second : " +s); 
	}
}

Output

Current Time : 11:54:28
Hour : 11
Minute : 54
Second : 28

Example Programs