
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,
- How to install Java 11 on Mac
- Get Client IP address from HTTP Response in Java
- SharePoint Open in the client application document opens in browser
- How to verify if java is installed on the computer and get version detail
- Java - Check if array contains the value
- Your JBoss Application Server 7 is running However you have not yet added any users to be able to access the admin console
- How to run Java Unit Test cases with Apache Maven?
- What Java version is used for Minecraft 1.18
- List of jar files for Jax-ws (SOAP) based Java Web Services
- [Fix] Java Exception with Lambda - Cannot invoke because object is null
- Convert Instant timestamp into LocalDateTime Java Code Example
- Java - Calculate time taken for the code to execute in milliseconds or nanoseconds
- Create simple struts2 project using maven commands
- Java - PatternSyntaxException
- List of Online Java compiler with console
- Minecraft Java Edition
- How to declare and initialize Array in Java Programming
- [Solved] com.sun.xml.ws.transport.http.servlet.WSServletContextListener ClassNotFoundException
- Java XML-RPC 3.1.x based web service example
- Simple Struts 2 Tutorial in eclipse with tomcat 7 server
- Java 8 foreach loop code examples
- Java -Day of the week using Java 8 DayOfWeek Enum
- Java 8 - Convert List to Map Examples
- Java: TimeZone List with GMT/UTC Offset
- list of jars required for hibernate 4.x.x
More Posts:
- Installation error: INSTALL_PARSE_FAILED_MANIFEST_MALFORMED - Android
- How to switch from bash to zsh shell in macOS Terminal - MacOS
- Android R Cannot Be Resolved To A Variable - Android
- Microsoft Teams Error code - 6 issue - Teams
- [Fix] java: incompatible types: incompatible parameter types in lambda expression error - Java
- How to make EditText text to uppercase or lowercase on macOS - MacOS
- How to change font, apply bold or italic styles, font size in Windows Notepad - HowTos
- 11 Weeks of Android Online Sessions-15-Jun-to-28-Aug-2020 - Android