When I wanted to create a method for Premium Friday, it was already in the Java 8 standard API

Former story I made a method to find Premium Friday --Qiita I made a method to find Premium Friday (Java 8 version) --Qiita I made a method to find Premium Friday in one liner --Qiita

In Java 8, I thought that it would be better to make TemporalAdjuster using the Date and Time API, and I already had it.

package premium.friday;

import java.time.DayOfWeek;
import java.time.LocalDate;
import java.time.YearMonth;
import java.time.format.DateTimeFormatter;
import java.time.temporal.TemporalAdjusters;

public class Main {
    public static void main(String[] args) {
        int[] years = {2017, 2018, 2019};
        for (int year : years) {
            for (int month = 1; month < 13; month++) {
                if (year == 2017 && month == 1) {
                    continue;
                }
                YearMonth yearMonth = YearMonth.of(year, month);
                LocalDate premiumFriday = yearMonth.atDay(1).with(TemporalAdjusters.lastInMonth(DayOfWeek.FRIDAY));
                System.out.println(premiumFriday.format(DateTimeFormatter.ofPattern("yyyy/MM/dd(E)")));
            }
        }
    }
}

TemporalAdjusters.lastInMonth(DayOfWeek.FRIDAY) You can get the last Friday of the month as it is.

Execution result


2017/02/24(Money)
2017/03/31(Money)
2017/04/28(Money)
2017/05/26(Money)
2017/06/30(Money)
2017/07/28(Money)
2017/08/25(Money)
2017/09/29(Money)
2017/10/27(Money)
2017/11/24(Money)
2017/12/29(Money)
2018/01/26(Money)
2018/02/23(Money)
2018/03/30(Money)
2018/04/27(Money)
2018/05/25(Money)
2018/06/29(Money)
2018/07/27(Money)
2018/08/31(Money)
2018/09/28(Money)
2018/10/26(Money)
2018/11/30(Money)
2018/12/28(Money)
2019/01/25(Money)
2019/02/22(Money)
2019/03/29(Money)
2019/04/26(Money)
2019/05/31(Money)
2019/06/28(Money)
2019/07/26(Money)
2019/08/30(Money)
2019/09/27(Money)
2019/10/25(Money)
2019/11/29(Money)
2019/12/27(Money)

Recommended Posts

When I wanted to create a method for Premium Friday, it was already in the Java 8 standard API
I made a method to ask for Premium Friday (Java 8 version)
I made a method to ask for Premium Friday
A story I was addicted to when testing the API using MockMVC
It was a life I wanted to reset the thread-safe associative counter
I tried to create a Clova skill in Java
[Words spelled to me when I was in the first grade ⑩] Please understand the minimum Java coding method. (1st: Naming)
I translated [Clone method for Java arrays] as the Clone method in Java arrays.
How to batch initialize arrays in Java that I didn't know when I was a beginner
[Words spelled to me when I was in the first grade ⑪] Please understand the minimum Java coding method. (2nd: Javadoc edition)
I want to create a chat screen for the Swift chat app!
Easy way to create a mapping class when using the API
[Java] I tried to make a maze by the digging method ♪
[Java] How to search for a value in an array (or list) with the contains method
Session was a cookie designed to be erased when the browser was closed and was a method for exchanging it: Rails Tutorial Note-What is a Rails Session?
Memorandum: What I was addicted to when I hit the accounting freee API
A story that I wanted to write a process equivalent to a while statement with the Stream API of Java8
Made a one-liner method for Premium Friday
I wanted to add @VisibleForTesting to the method
I was addicted to the roll method
I called the COTOHA API parser 100 times in Java to measure performance.
I want to get the IP address when connecting to Wi-Fi in Java
I thought about the best way to create a ValueObject in Ruby
How to reference a column when overriding the column name method in ActiveRecord
What I did when I was addicted to the error "Could not find XXX in any of the sources" when I added a Gem and built it
I tried to create a method to apply multiple filters at once with Java Stream API. Is this okay?
What I tried when I wanted to get all the fields of a bean
[Java] I checked it because it was erratic when converting the type. <Cast operator>
[Java] Is it unnecessary to check "identity" in the implementation of the equals () method?
[Azure] I tried to create a Java application for free-Web App creation- [Beginner]
ChatWork4j for using the ChatWork API in Java
Try to create a bulletin board in Java
I tried to create Alexa skill in Java
[Java] When putting a character string in the case of a switch statement, it is necessary to make it a constant expression
Rspec: I want to test the post-execution state when I set a method on subject
I wrote a test code (Junit & mockit) for the code that calls the AWS API (Java)
A note for when someone who was Java Java until yesterday came to touch Scala
When making a personal app, I was wondering whether to make it using haml
You don't have to write for twice when you make a right triangle in Java
A study method for inexperienced people to pass Java SE 8 Silver in one month
The part I was addicted to in "Introduction to Ajax in Java Web Applications" of NetBeans
[Azure] I tried to create a Java application for free ~ Connect with FTP ~ [Beginner]
I was addicted to the NoSuchMethodError in Cloud Endpoints
How to create a Java environment in just 3 seconds
How to create a data URI (base64) in Java
A note for Initializing Fields in the Java tutorial
I tried to make a login function in Java
What I learned when building a server in Java
I tried to implement the Euclidean algorithm in Java
I want to create a generic annotation for a type
Java: A story that made me feel uncomfortable when I was taught to compare strings with equals for no reason.
When I switched to IntelliJ, I got a lot of differences in the encoding of the properties file.
[Self-directed daily posting festival] The reason why I was able to enter into a Java development project in two years from my inexperience in IT at SES
Implemented a strong API for "I want to display ~~ on the screen" with simple CQRS
Click the [rails] button to create a random alphanumeric password and enter it in the password field
Generics Metamorphosis Grammar-RealmObject backup-I thought it was a pain to write RealmMigration during development but I wanted to take over the data-
How to get the class name / method name running in Java
I tried to create a java8 development environment with Chocolatey
What I was addicted to when introducing the JNI library
Failed to create the Java Virtual Machine when installing Eclipse.
[Beginner] I made a program to sell cakes in Java