Home  >  Article  >  Java  >  How to check periodic events like birthdays in Java 8

How to check periodic events like birthdays in Java 8

WBOY
WBOYforward
2023-05-12 23:10:041293browse

Checking for periodic events like birthdays in Java 8

package com.shxt.demo02;  
import java.time.LocalDate;  
import java.time.MonthDay;  
public class Demo05 {      
public static void main(String[] args) {          
LocalDate date1 = LocalDate.now();          
LocalDate date2 = LocalDate.of(2018,2,6);          
MonthDay birthday = MonthDay.of(date2.getMonth(),date2.getDayOfMonth());          
MonthDay currentMonthDay = MonthDay.from(date1);          
if(currentMonthDay.equals(birthday)){              
System.out.println("是你的生日");          
}else{              
System.out.println("你的生日还没有到");          
}      
}  
}

As long as the date of the day matches the birthday, the congratulatory message will be printed no matter which year it is. You can integrate the program into the system clock to see if you are reminded of birthdays, or write a unit test to check whether the code runs correctly.

The above is the detailed content of How to check periodic events like birthdays in Java 8. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:yisu.com. If there is any infringement, please contact admin@php.cn delete