Convert day of week number to Day string

Asked

Viewed 219 times

0

I need to convert the number that corresponds to the day of the week in String of the day in Java. Ex:

0 => Monday
1 => Tuesday
  • I mean, you want weeks starting on Monday?

1 answer

11


You can use the DayOfWeek for this, example:

import java.time.DayOfWeek;

public class Main {

    public static void main (String[] args) {
        System.out.println("1 = " + DayOfWeek.of(1));
        System.out.println("2 = " + DayOfWeek.of(2));
        System.out.println("3 = " + DayOfWeek.of(3));
        System.out.println("4 = " + DayOfWeek.of(4));
        System.out.println("5 = " + DayOfWeek.of(5));
        System.out.println("6 = " + DayOfWeek.of(6));
        System.out.println("7 = " + DayOfWeek.of(7));
    }

}

See working on repl it.

You can see a few more examples: Dayofweek and Month Enums

Browser other questions tagged

You are not signed in. Login or sign up in order to post.