How can we add or subtract date in java? For instance java.sql.Date and formatted like this: yyyy-MM-dd, how can i Add 5 months from that? I’ve seen in some tutorial that they are using Calendar, can we set date on it? Please Help.
Example: 2012-01-01 when added 5 months will become 2012-06-01.
PS: I’m a .Net Programmer and slowly learning to Java environment.
First of all you have to convert your
Stringdate tojava.util.Date, than you have to usejava.util.Calendarto manipulate dates. It is also possible to do math with millis, but I do not recommend this.