Write a Java program to print ZonedDateTime E MMM yyyy HH:mm:ss.SSSZ


This Java program retrieves the current system date, time, and timezone information and formats it as a string in the pattern "E MMM yyyy HH:mm:ss.SSSZ". The ZonedDateTime class from the java.time package is used to obtain the current date, time, and timezone information. The DateTimeFormatter class is then used to format the date, time, and timezone information in the desired pattern. The formatted date, time, and timezone information are then assigned to a string variable dt, which is printed to the console using System.out.println(). Overall, this program is useful for getting the current date, time, and timezone information in a specific format, which can be useful for various applications that require timezone information.

Source Code

import java.time.ZonedDateTime;
import java.time.format.DateTimeFormatter;
class Zoned_DateTime
{
	public static void main(String Args[])
	{
		String dt;
		ZonedDateTime zdt = ZonedDateTime.now();
		DateTimeFormatter formatterZonedDateTime = DateTimeFormatter.ofPattern("E MMM yyyy HH:mm:ss.SSSZ");
		dt = formatterZonedDateTime.format(zdt);
		System.out.println("E MMM yyyy HH:mm:ss.SSSZ = " + dt);
	}
}

Output

E MMM yyyy HH:mm:ss.SSSZ = Sat Nov 2022 12:41:28.940+0530

Example Programs