- Trending Categories
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
Get the Day of the Week from Today's Date in Java
To get the day of the week, use the Calendar.DAY_OF_WEEK.
Firstly, let us get the current date.
java.util.Date utilDate = new java.util.Date(); java.sql.Date dt = new java.sql.Date(utilDate.getTime());
Now, using GregorianCalendar, set the time.
java.util.GregorianCalendar cal = new java.util.GregorianCalendar(); cal.setTime(dt);
The last step would display the day of the week as shown in the following example.
Example
import java.text.ParseException; public class Demo { public static void main(String[] args) throws ParseException { java.util.Date utilDate = new java.util.Date(); java.sql.Date dt = new java.sql.Date(utilDate.getTime()); System.out.println("Today's date: "+dt); java.util.GregorianCalendar cal = new java.util.GregorianCalendar(); cal.setTime(dt); // Getting the day of the week System.out.println("Day of the week: "+cal.get(java.util.Calendar.DAY_OF_WEEK)); } }
Output
Today's date: 2018-11-19 Day of the week: 2
- Related Articles
- Get the day of week for a particular date in Java
- Java Program to get the day of the week from GregorianCalendar
- Get Day Number of Week in Java
- Finding day of week from date (day, month, year) in JavaScript
- Get the week number in MySQL for day of week?
- Python Pandas - Get the day of the week from the PeriodIndex object
- Get the day from a date in Pandas
- Java Program to get day of week for the last day of each month in 2019
- Get localized short day-in-week name in Java
- Java Program to get day of week as string
- How to get the day of the week in JavaScript?
- Java Program to get the beginning and end date of the week
- How to get day of month, day of year and day of week in android using offset date time API class?
- Java Program to get date for all the days of the current week
- In MySQL, how we can compute date by providing the year, week number and day of the week?\nday of the week?

Advertisements