[Java] Get the day of the specific day of the week

As a memorandum

It's easy to use LocalDate.


//today
LocalDate now = LocalDate.now();    // 2020-06-23: Tuesday

//this Friday
LocalDate thisFriday = now.with(DayOfWeek.FRIDAY);    // 2020-06-26

//Last wednesday
LocalDate lastWednesDay = now.minusWeeks(1).with(DayOfWeek.WEDNESDAY);    // 2020-06-17

//Next thursday
LocalDate nextThursDay = now.plusWeeks(1).with(DayOfWeek.THURSDAY);    // 2020-07-02

//Bonus: Convert to LocalDateTime
LocalDateTime from = lastWednesDay.atTime(00, 00, 00);    // 2020-06-17 00:00:00

reference

Date and Time API Tips for Japanese (ja) [Java] Get the dates of the past Monday and Sunday in order @ kazokclily

Recommended Posts

[Java] Get the day of the specific day of the week
[Java1.8 +] Get the date of the next x day of the week with LocalDate
How to get today's day of the week
Get the result of POST in Java
[day: 5] I summarized the basics of Java
Zeller's official (asking for the day of the week)
[Java] Get the length of the surrogate pair string
[Ruby] Code to display the day of the week
[Java] How to get to the front of a specific string using the String class
[Java] How to get the URL of the transition source
Get the URL of the HTTP redirect destination in Java
[Ubuntu 20.04] Display the day of the week on the date / clock
4th day of java learning
[Java] How to get the maximum value of HashMap
[Java] Get the file in the jar regardless of the environment
Output of the day of the week using Ruby's Date class
[Java] Calculate the day of the week from the date (Calendar class is not used)
Java is the 5th day
[Java] How to display the day of the week acquired by LocalDate, DateTimeformatter in Japanese
Was done in the base year of the Java calendar week
Get to the abbreviations from 5 examples of iterating Java lists
How to derive the last day of the month in Java
[Java] Delete the elements of List
Get the ID of automatic numbering
The origin of Java lambda expressions
Java Day 2018
[Java] Get the dates of the past Monday and Sunday in order
Java, JS (jQuery) and Ajax. Get a specific value of JSON.
Get the public URL of a private Flickr file in Java
Change the conversation depending on which day of the week is today
How to get the length of an audio file in java
Check the contents of the Java certificate store
Examine the memory usage of Java elements
Memo: [Java] Check the contents of the directory
Compare the elements of an array (Java)
[Java] How to get the current directory
What are the updated features of java 13
Easily measure the size of Java Objects
Looking back on the basics of Java
How to get the date in java
Output of the book "Introduction to Java"
The story of writing Java in Emacs
[Java8] Search the directory and get the file
[Java] Check the number of occurrences of characters
[Java] [Spring] Test the behavior of the logger
[Java] Get the date with the LocalDateTime class
How to get the absolute path of a directory running in Java
I want to get the field name of the [Java] field. (Old tale tone)
[Java] Get MimeType from the contents of the file with Apathce Tika [Kotlin]
Display Japanese calendar and days of the week using java8 standard class
[Java] Handling of JavaBeans in the method chain
JAVA: jar, aar, view the contents of the file
The story of making ordinary Othello in Java
[Android] [Java] Manage the state of CheckBox of ListView
About the description order of Java system properties
About the idea of anonymous classes in Java
Java learning day 5
The order of Java method modifiers is fixed
[Java] Access the signed URL of s3 (signed version 2)
The story of learning Java in the first programming
Measure the size of a folder in Java