w3resource

Java: Get the minimum value of year, month, week, date from the current date of a default calendar


Write a Java program to get the minimum value of year, month, week, date from the current date of a default calendar.

Sample Solution:

Java Code:

import java.util.*;
public class Exercise4 {
 public static void main(String[] args)
    {
     // Create a default calendar
        Calendar cal = Calendar.getInstance();
		System.out.println();
		System.out.println("\nCurrent Date and Time:" + cal.getTime());		
		int actualMaxYear = cal.getActualMinimum(Calendar.YEAR);
		int actualMaxMonth = cal.getActualMinimum(Calendar.MONTH);
		int actualMaxWeek = cal.getActualMinimum(Calendar.WEEK_OF_YEAR);
		int actualMaxDate = cal.getActualMinimum(Calendar.DATE);
		
		System.out.println("Actual Minimum Year: "+actualMaxYear);
		System.out.println("Actual Minimum Month: "+actualMaxMonth);
		System.out.println("Actual Minimum Week of Year: "+actualMaxWeek);
		System.out.println("Actual Minimum Date: "+actualMaxDate+"\n");
		System.out.println();		
	  }
}

Sample Output:

Current Date and Time:Tue Jun 20 14:29:35 IST 2017                                                            
Actual Minimum Year: 1                                                                                        
Actual Minimum Month: 0                                                                                       
Actual Minimum Week of Year: 1                                                                                
Actual Minimum Date: 1

N.B.: The result may varry for your system date and time.

Flowchart:

Flowchart: Java DateTime, Calendar Exercises - Get the minimum value of year, month, week, date from the current date of a default calendar

For more Practice: Solve these Related Problems:

  • Write a Java program to extract and display the minimum values for year, month, day, and week from a Calendar instance.
  • Write a Java program to list minimum allowable values for various Calendar fields and compare them with maximum values.
  • Write a Java program to display the minimum value for the day of month and week of month from the default Calendar.
  • Write a Java program to calculate the difference between maximum and minimum field values for a given date.

Java Code Editor:

Improve this sample solution and post your code through Disqus

Previous: Write a Java program to get the maximum value of the year, month, week, date from the current date of a default calendar.
Next: Write a Java program to get the current time in New York.

What is the difficulty level of this exercise?

Test your Programming skills with w3resource's quiz.



Follow us on Facebook and Twitter for latest update.