![Get Day of the week as Int Java Example Get Day of the week as Int Java Example](https://code2care.org/java/java-get-day-of-the-week-as-int-dayofweek/images/Get Day of the week as Int Java Example.png)
To get the day of the week as an int, make use of the getValue() from the DayOfWeek class from Java Date & Time API (java.time),
Code Snippet:
//Example 1
LocalDate localDateNow = LocalDate.now();
DayOfWeek dayOfWeek = localDateNow.getDayOfWeek();
int dayOfWeekAsInt = dayOfWeek.getValue();
System.out.println("Day of week for "+localDateNow+" as an int: " + dayOfWeekAsInt);
//Example 2
LocalDate localDate20200101 = LocalDate.of(2020,01,01);
DayOfWeek dayOfWeekFor20200101 = localDate20200101.getDayOfWeek();
int dayOfWeekAsIntFor20200101 = dayOfWeekFor20200101.getValue();
System.out.println("Day of week for "+localDate20200101+" as an int: " + dayOfWeekAsIntFor20200101);
Day of the week for 2022-05-14 as an int: 6
Day of the week for 2020-01-01 as an int: 3
More Posts related to Java,
- Get the current timestamp in Java
- Java Stream with Multiple Filters Example
- Java SE JDBC with Prepared Statement Parameterized Select Example
- Fix: UnsupportedClassVersionError: Unsupported major.minor version 63.0
- [Fix] Java Exception with Lambda - Cannot invoke because object is null
- 7 deadly java.lang.OutOfMemoryError in Java Programming
- How to Calculate the SHA Hash Value of a File in Java
- Java JDBC Connection with Database using SSL (https) URL
- How to Add/Subtract Days to the Current Date in Java
- Create Nested Directories using Java Code
- Spring Boot: JDBCTemplate BatchUpdate Update Query Example
- What is CA FE BA BE 00 00 00 3D in Java Class Bytecode
- Save Java Object as JSON file using Jackson Library
- Adding Custom ASCII Text Banner in Spring Boot Application
- [Fix] Java: Type argument cannot be of primitive type generics
- List of New Features in Java 11 (JEPs)
- Java: How to Add two Maps with example
- Java JDBC Transition Management using PreparedStatement Examples
- Understanding and Handling NullPointerException in Java: Tips and Tricks for Effective Debugging
- Steps of working with Stored Procedures using JDBCTemplate Spring Boot
- Java 8 java.util.Function and BiFunction Examples
- The Motivation Behind Generics in Java Programming
- Get Current Local Date and Time using Java 8 DateTime API
- Java: Convert Char to ASCII
- Deep Dive: Why avoid java.util.Date and Calendar Classes
More Posts:
- [Fix] Notepad Error: Windows cannot access the specified Device or Path - Windows-11
- How to install Microsoft OneDrive on Mac Sonoma 14 - MacOS
- Java 8 Predicate default and() function Example - Java
- How to turn off Dark theme in Excel for Mac - Microsoft
- Adding Sub Headings to Bootstrap Header tags - Html
- Change Terminal Cursor Type in Mac (MacOS Shell) - MacOS
- Base64 Encoding Decoding in Python Programming - Python
- Docker - Running in Resource Saver mode - Docker