Skip to content
Advertisement

How to set an expiration date in java

I am trying to write some code to correctly set an expiration date given a certain date.

For instance this is what i have.

JavaScript

However, say if i the sign up date is on 5/7/2011 the expiration date output i get is on 11/6/2011 which is not exactly half of a year from the given date. Is there an easier way to do this?

Advertisement

Answer

I would use the Calendar class – the add method will do this kind of thing perfectly.

http://download.oracle.com/javase/6/docs/api/java/util/Calendar.html

JavaScript
User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement