Java: check if a given date is within current month
问题 I need to check if a given date falls in the current month, and I wrote the following code, but the IDE reminded me that the getMonth() and getYear() methods are obsolete. I was wondering how to do the same thing in newer Java 7 or Java 8. private boolean inCurrentMonth(Date givenDate) { Date today = new Date(); return givenDate.getMonth() == today.getMonth() && givenDate.getYear() == today.getYear(); } 回答1: Time Zone The other answers ignore the crucial issue of time zone. A new day dawns