Java Date - How to write "If date A is later than date B" -
i'm asked write expiry method policy expires in 1 year after it's added. wrote method adds 1 year initial date added.
now i'm trying write method returns boolean see if date past date b. if it's past, means it's expired, it'll homecoming true. can help me out syntax, not sure here. give thanks you
public expirablepolicy(float a, date d){ super(a); amount = a; expirydate = new date(); gregoriancalendar acalendar = new gregoriancalendar(); acalendar.add(calendar.year,1); expirydate = acalendar.gettime(); } public boolean isexpired(){ //expiry method;
this can done date.before()
or date.after()
:
if (d.after(expirydate)) { ... }
or
if (!d.before(expirydate)) { ... }
the first comparing evaluates true
d
strictly greater expirydate
. sec evaluates true
if d
greater or equal expirydate
.
the same effect can achieved date.compareto()
.
java
No comments:
Post a Comment