Write a Java program to print OffsetTime HH:mm:ss,Z


This Java program retrieves the current system time and timezone offset information and formats it as a string in the pattern "HH:mm:ss,Z". The OffsetTime class from the java.time package is used to obtain the current time and timezone offset information. The DateTimeFormatter class is then used to format the time and timezone offset information in the desired pattern. The formatted time and timezone offset information are 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 and timezone offset information in a specific format, which can be useful for various applications that require timezone offset information.

Source Code

import java.time.OffsetTime;
import java.time.format.DateTimeFormatter;
class Offset_DateTime
{
	public static void main(String Args[])
	{
		String t;
		OffsetTime ost = OffsetTime.now();
		DateTimeFormatter formatterOffsetTime = DateTimeFormatter.ofPattern("HH:mm:ss,Z");
		t = formatterOffsetTime.format(ost);
		System.out.println("HH:mm:ss,Z = " + t);
	}
}

Output

HH:mm:ss,Z = 12:43:02,+0530

Example Programs