
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,
- Drop table using Java JDBC Template
- Java - Check if array contains the value
- YAML Parser using Java Jackson Library Example
- Java Jackson ObjectMapper Class with Examples
- Get Client IP address from HTTP Response in Java
- How to Word-Warp Console logs in IntelliJ
- Exception in thread main java.lang.NoClassDefFoundError: package javaClass
- Setting Java_Home Environment variable on Windows Operating System
- Fix: Maven - Failed to execute goal - Compilation failure - Source/Target option 5 is no longer supported. Use 7 or later
- Java SE JDBC Select Statement Example
- How to extract Java Jar/War/Ear files in Linux
- java: unclosed string literal [Error]
- [Solution] Exception in thread main java.util.EmptyStackException
- Read YAML file Java Jackson Library
- What Java version is used for Minecraft 1.18
- [Java] How to throws Exception using Functional Interface and Lambda code
- [Program] How to read three different values using Scanner in Java
- Java 8 Predicate Functional Interface Examples
- Display Era details (AD BC) in Java Date using SimpleDateFormat
- Convert String Date to Date Object in Java
- Struts 2 Hello World Example in Eclipse
- Read a file using Java 8 Stream
- Java - How to set custom thread name?
- IntelliJ: Error: Could not find or load main class, java.lang.ClassNotFoundException
- java: ']' expected error [fixed]
More Posts:
- List of jars required for Struts2 project - Java
- Background task activation is spurious error - Windows 10, Office 2016, Office 365 - HowTos
- Go to Specific file path using Mac Finder - MacOS
- Convert Float to String in Python - Python
- Install the minimal Linux on Docker (only 5 mb Alpine Linux) - Docker
- How to fix: Please check your network connection (Retry) - HowTos
- Check Wifi Connection static Android Programming - Android
- 'pwd' is not recognized as an internal or external command, operable program or batch file. [Windows] - Bash