- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- MS Excel
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP
- Physics
- Chemistry
- Biology
- Mathematics
- English
- Economics
- Psychology
- Social Studies
- Fashion Studies
- Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Determine day of week in month from Gregorian Calendar in Java
To work with the GregorianCalendar class, import the following package −
import java.util.GregorianCalendar;
To get the day of week in month, use the following field −
cal.get(Calendar.DAY_OF_WEEK_IN_MONTH)
Above, cal is the GregorianCalendar object we created before −
GregorianCalendar cal = new GregorianCalendar();
The following is an example −
Example
import java.util.GregorianCalendar; import java.util.Calendar; import java.util.Date; public class Demo { public static void main(String[] args) { GregorianCalendar cal = new GregorianCalendar(); // date information System.out.println("Date Information.........."); System.out.println("Year = " + cal.get(Calendar.YEAR)); System.out.println("Month = " + (cal.get(Calendar.MONTH) + 1)); System.out.println("Date = " + cal.get(Calendar.DATE)); // week System.out.println("Day of Week in month = " + cal.get(Calendar.DAY_OF_WEEK_IN_MONTH)); } }
Output
Date Information.......... Year = 2018 Month = 11 Date = 19 Day of Week in month = 3
Advertisements
To Continue Learning Please Login
Login with Google