• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 219
  • Last Modified:

Java Calendar Class

Hi,

I currently have a method that takes the current time and date and returns the date 3 weeks later, I want to change this to 10 calendar days later.

public Date createFirstDateFromDirectDebitDate()
      {
            Calendar firstAllowable = Calendar.getInstance();
            
            /* set calendar value to 3 weeks time */
            firstAllowable.setTime(new Date());
            firstAllowable.add(Calendar.WEEK_OF_YEAR, 3);
            
            return firstAllowable.getTime();
      }

I tried using DAY_OF_YEAR but it seems to only give me 10 working days later

firstAllowable.add(Calendar.DAY_OF_YEAR, 10);

Can anyone tell what im doing wrong??

Thanks
Suzy
0
fyness
Asked:
fyness
1 Solution
 
CEHJCommented:
TRY

firstAllowable.add(Calendar.DATE, 10);
0
 
TimYatesCommented:
firstAllowable.add(Calendar.DAY_OF_YEAR, 10);

should work
0
 
girionisCommented:
> firstAllowable.add(Calendar.DAY_OF_YEAR, 10);

It should do. Maybe you are mistaken, can you double check?
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
CEHJCommented:
What you have should work, although my version needs less typing ;-)

>>firstAllowable.setTime(new Date());

is redundant btw as Calendar is already initialized with the current date
0
 
TimYatesCommented:
> although my version needs less typing ;-)

LOL ;-)
0
 
fynessAuthor Commented:
Thanks for your replys but still no luck. I've double checked and am still having trouble, I even tried changing DAY_OF_WEEK from 10 to 6 and its the same problem. I also tried using Calendar.DATE and still no joy!

There must be another problem that i dont see yet

Thanks again for your help!
0
 
TimYatesCommented:
can you post more of your code?

This *does* work...
0
 
CEHJCommented:
>>There must be another problem that i dont see yet

It will probably amount to not using the Date that you returned from your method ;-)
0
 
thomasbauCommented:
This has to work


  public Date createFirstDateFromDirectDebitDate()
     {
          Calendar firstAllowable = Calendar.getInstance();
          Date date = new Date();
          /*
           *Add 10 days*/
          long offset = date.getTime();
          long milPerDay = 24*60*60*1000;
          offset += 10 * milPerDay;
          date.setTime(offset);
         
          /*
           *Set the new date in the calendar*/
          firstAllowable.setTime(date);
          /* set calendar value to 3 weeks time */
          //firstAllowable.setTime(new Date());
          //firstAllowable.add(Calendar.WEEK_OF_YEAR, 3);
         
          return firstAllowable.getTime();
     }

0
 
Mayank SAssociate Director - Product EngineeringCommented:
Are you using two firstAllowable.add () statements anywhere?
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now