×

Java Programs

Java Practice

Java program to get the current day number of a month using the get() method of Calendar class

Learn how to get the current day number of a month using the get() method of Calendar class in Java?
Submitted by Nidhi, on April 01, 2022

Problem statement

Create an instance of the Calendar class and get the current day number of the month using the get() method, and printed the result.

Source Code

The source code to get the current year using the get() method of the Calendar class is given below. The given program is compiled and executed successfully.

// Java program to get the current day number of the month 
// using the get() method of Calendar class

import java.util.*;

public class Main {
  public static void main(String[] args) {
    Calendar cal = Calendar.getInstance();

    System.out.println("Current Day: " + cal.get(Calendar.DATE));
  }
}

Output

Current Day: 1

Explanation

In the above program, we created a class Main that contains a static method main(). The main() method is the entry point for the program, here we created the object of the Calendar class and got the current day of the number using the get() method, and printed the result.

Java Date and Time Programs »



Related Programs



Comments and Discussions!

Load comments ↻





Copyright © 2024 www.includehelp.com. All rights reserved.