This Java program retrieves the current system time and formats it as a string in the pattern "HH:mm:ss". The LocalTime class from the java.time package is used to obtain the current time. The DateTimeFormatter class is then used to format the time in the desired pattern. The formatted time is then assigned to a string variable t, which is printed to the console using System.out.println(). Overall, this program is useful for getting the current time in a specific format, which can be useful for various applications.
import java.time.LocalTime; import java.time.format.DateTimeFormatter; class Local_Time { public static void main(String Args[]) { String t; LocalTime lt = LocalTime.now(); DateTimeFormatter formatterLocalTime = DateTimeFormatter.ofPattern("HH:mm:ss"); t = formatterLocalTime.format(lt); System.out.println("HH:mm:ss = " + t); } }
HH:mm:ss = 12:38:04
Learn All in Tamil © Designed & Developed By Tutor Joes | Privacy Policy | Terms & Conditions