954,541 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Date

Hi all,

I want to create a function that adds certain amount of days for a given date.

e.g.

Say today's date is 21/9/2007. and I would like to add 95 days to this date. How do I accomplish that.

Any help will be real appreciate it.

Regards.

new_2_java
Junior Poster
127 posts since Apr 2007
Reputation Points: 7
Solved Threads: 6
 

The folowing link of java util API can provide help.
http://72.5.124.55/j2se/1.5.0/docs/api/java/util/GregorianCalendar.html#add(int,%20int )

There was another DateUtility which was posted earlier on this site. Please refer that too.

lookof2day
Junior Poster in Training
83 posts since Aug 2007
Reputation Points: 16
Solved Threads: 11
 

You will want to use Calendar (or perhaps specifically GregorianCalendar ) class for that. This site has a lot of info on using it: http://mindprod.com/jgloss/calendar.html
Adding time (days, weeks, months, whatever) is a simple matter of using the add() method or the roll() method depending on your needs.
Calendar now = Calendar.getInstance(); will give you a locale-specific instance of a Calendar set to the current date and time.

Ezzaral
Posting Genius
Moderator
15,986 posts since May 2007
Reputation Points: 3,250
Solved Threads: 847
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You