 
  Data Structure Data Structure
 Networking Networking
 RDBMS RDBMS
 Operating System Operating System
 Java Java
 MS Excel MS Excel
 iOS iOS
 HTML HTML
 CSS CSS
 Android Android
 Python Python
 C Programming C Programming
 C++ C++
 C# C#
 MongoDB MongoDB
 MySQL MySQL
 Javascript Javascript
 PHP PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Get Day Number of Week in Java
To get the day of the week, use Calendar.DAY_OF_WEEK.
Firstly, declare a calendar object and get the current date and time.
Calendar calendar = Calendar.getInstance(); System.out.println(calendar.getTime().toString());
Now, fetch the day of the week in an integer variable.
int day = calendar.get(Calendar.DAY_OF_WEEK);
The following is the final example.
Example
import java.util.Calendar; public class Demo {    public static void main(String[] args) {       Calendar calendar = Calendar.getInstance();       System.out.println(calendar.getTime().toString());       int day = calendar.get(Calendar.DAY_OF_WEEK);       System.out.println("Day: " + day);       int hour = calendar.get(Calendar.HOUR_OF_DAY);       System.out.println("Hour: " + hour);       int minute = calendar.get(Calendar.MINUTE);       System.out.println("Minute: " + minute);    } }  Output
Mon Nov 19 10:11:41 UTC 2018 Day: 2 Hour: 10 Minute: 11
Advertisements
 