• Post Reply Bookmark Topic Watch Topic
  • New Topic

Calendar arithmetic  RSS feed

 
amir asyraf
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
now i already get the current date and expire date after 5 days, now im confuse how to use if/else, if the expired date is not reach it will shown output "false". how should i do that?.

my code:
 
Les Morgan
Rancher
Posts: 779
19
C++ Java MySQL Database Netbeans IDE Oracle Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You have "before" and "after" that you can use it's very simple:

return myCalendar.before(newCalendar): // returns true if the date is before myCalendar;

return myClaendar.after(newCalendar); // returns true if new Calendar is after myCalendar;
 
Campbell Ritchie
Marshal
Posts: 56570
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Stop using Calendar. A really dreadful class. Use LocalDate instead: look in the Java™ Tutorials for more information. The tutorials might even tell you how to use before and after.
 
Indigo Montes
Greenhorn
Posts: 22
1
C++ IntelliJ IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you (can) use Java 8 (or 9), then you might consider using the new Date & Time API. For dates, you can use class java.time.LocalDate.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!