- 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
Java Program to get the day of the week from GregorianCalendar
For GregorianCalendar class, import the following package.
import java.util.GregorianCalendar;
Create an object.
GregorianCalendar calendar = new GregorianCalendar();
To get the day of the week, use the following field.
GregorianCalendar.DAY_OF_WEEK
The following is an example.
Example
import java.util.Calendar; import java.util.GregorianCalendar; public class Demo { public static void main(String[] a) { GregorianCalendar calendar = new GregorianCalendar(); System.out.println("Day of Week = " + calendar.get(GregorianCalendar.DAY_OF_WEEK)); System.out.println("Date = " + calendar.get(GregorianCalendar.DATE)); System.out.println("Month = " + calendar.get(GregorianCalendar.MONTH)); System.out.println("Year = " + calendar.get(GregorianCalendar.YEAR)); } }
Output
Day of Week = 2 Date = 19 Month = 10 Year = 2018
Advertisements
To Continue Learning Please Login
Login with Google