- 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 day of week as string
To get day of week as string, first let us display the current date −
LocalDate currentDate = LocalDate.now();
Now, use DayOfWeek to get the day of week from the current date −
DayOfWeek day = currentDate.getDayOfWeek();
Get the day of week as string −
String weekName = day.name();
Example
import java.time.DayOfWeek; import java.time.LocalDate; public class Demo { public static void main(String[] args) { LocalDate currentDate = LocalDate.now(); System.out.println("Current Date = "+currentDate); DayOfWeek day = currentDate.getDayOfWeek(); int weekVal = day.getValue(); String weekName = day.name(); System.out.println("Week Number = "+weekVal); System.out.println("Week Name = "+weekName); } }
Output
Current Date = 2019-04-12 Week Number = 5 Week Name = FRIDAY
Advertisements