- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
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
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
- Related Articles
- Get the week number in MySQL for day of week?
- Java Program to get day of week as string
- Get localized short day-in-week name in Java
- Get the day of week for a particular date in Java
- Java Program to get day of week for the last day of each month in 2019
- Java Program to get the day of the week from GregorianCalendar
- Get the Day of the Week from Today's Date in Java
- Java Program to get display name for Day of Week in different locale
- How to get first day of week in PHP?
- C# Program to get current day of week
- Formatting day of week using SimpleDateFormat in Java
- How to get the day of the week in JavaScript?
- Formatting day of week in EEEE format in Java
- Display Day Name of Week using Java Calendar
- How to get first day of the week using Python?

Advertisements