This Java program uses the Calendar class to obtain the current date and time, and then prints out the values of several fields using the get() method.
The program prints out the following date and time fields:
Note that the program uses Calendar.getInstance() method to create a new Calendar instance that represents the current date and time in the default time zone and locale. The values of the date and time fields depend on the system clock and time zone settings.
Also note that the program prints out the hour value in 12-hour clock format (Calendar.HOUR), which may not be appropriate in all contexts. To obtain the hour value in 24-hour clock format, use the Calendar.HOUR_OF_DAY field instead.
import java.util.*; public class Display_Default_Calendar { public static void main(String[] args) { Calendar c = Calendar.getInstance(); System.out.println("Day : " + c.get(Calendar.DATE)); System.out.println("Month : " + c.get(Calendar.MONTH)); System.out.println("Year : " + c.get(Calendar.YEAR)); System.out.println("Hour : " + c.get(Calendar.HOUR)); System.out.println("Minute : " + c.get(Calendar.MINUTE)); } }
Day : 5 Month : 10 Year : 2022 Hour : 2 Minute : 22
Learn All in Tamil © Designed & Developed By Tutor Joes | Privacy Policy | Terms & Conditions