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

karthikeya Boyini
karthikeya Boyini

I love programming (: That's all I know

Updated on: 30-Jul-2019

997 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements