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

How to check periodic events like birthdays in Java 8

WBOY
Release: 2023-05-12 23:10:04
forward
1319 people have browsed it

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("你的生日还没有到");          
}      
}  
}
Copy after login

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!

Related labels:
source:yisu.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template