• Post Reply Bookmark Topic Watch Topic
  • New Topic

Date increment help  RSS feed

 
jeffrey ngg
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi guys,
i'm currently doing a project using netbeans which is about warranty

using jCalendar 1.4.jar as my jDateChooser


i want to let it increment by a year whenever i put in my registration date.
Example: i put choose the date in "registration date" 2009-09-09, in the "Expiration date" it will auto increment by a year which will display 2010-09-09.

may i know where should i put the code in and what's the code i should type in to make this work?
 
Campbell Ritchie
Marshal
Posts: 56518
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to the Ranch

We do not operate like that; we expect you to show what you have already. Which date applet is that? Is it Tödter's? What does it return? Have you been through the API for that class?
 
Winston Gutkowski
Bartender
Posts: 10575
66
Eclipse IDE Hibernate Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
jeffrey ngg wrote:i want to let it increment by a year whenever i put in my registration date.
Example: i put choose the date in "registration date" 2009-09-09, in the "Expiration date" it will auto increment by a year which will display 2010-09-09.
may i know where should i put the code in and what's the code i should type in to make this work?

Sure you may. And welcome to JavaRanch jeffrey.

Have a look at the Calendar interface (java.util.Calendar; and I warn you: it's big). What you'll actually want is GregorianCalendar, which implements it.

Specifically, have a look at the add() method, because that's what you'll need.

Unfortunately, Java doesn't have a class that ONLY holds a date (more's the pity), which means that there's a time hidden in there as well; but for the purposes of your program you can ignore it.

Winston

[Edit: Oops. After Campbell's post, it appears jeffrey's question might be more specific than I was thinking. However, I leave my answer up in case it's useful.]
 
Campbell Ritchie
Marshal
Posts: 56518
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Your posts are always relevant, WG.

JN: You probably get an instance of the Calendar class and you can use its add(int, int) method to get one year in advance. Be sure to read about Calendar before using it. The standard Java date‑and‑time classes are pretty dreadful, I am afraid.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!