This Java program uses the Calendar class to obtain the current date and time and then determines the maximum value for various date and time fields using the getActualMaximum() method.
The getActualMaximum() method returns the maximum value that can be assigned to a particular field of the Calendar instance, taking into account the current value of other fields. For example, the maximum value of the Calendar.DATE field may depend on the current month and year.
The program prints out the maximum value of the following fields:
Note that the getActualMaximum() method returns different values depending on the time zone and locale settings of the Calendar instance. Also, the program does not prompt the user for input or perform any other meaningful computation beyond obtaining the maximum values of the date and time fields.
import java.util.*; public class Maximum_ValDate { public static void main(String[] args) { Calendar cal = Calendar.getInstance(); System.out.println("Current Date and Time:" + cal.getTime()); int maxDate = cal.getActualMaximum(Calendar.DATE); int maxMonth = cal.getActualMaximum(Calendar.MONTH); int maxYear = cal.getActualMaximum(Calendar.YEAR); int maxWeek = cal.getActualMaximum(Calendar.WEEK_OF_YEAR); System.out.println("Maximum Value of Date: "+maxDate); System.out.println("Maximum Value of Month: "+maxMonth); System.out.println("Maximum Value of Year: "+maxYear); System.out.println("Maximum Value of Week of Year: "+maxWeek); } }
Current Date and Time:Sat Nov 05 14:21:16 IST 2022 Maximum Value of Date: 30 Maximum Value of Month: 11 Maximum Value of Year: 292278993 Maximum Value of Week of Year: 53
Learn All in Tamil © Designed & Developed By Tutor Joes | Privacy Policy | Terms & Conditions