#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2002
    Location
    England
    Posts
    8
    Rep Power
    0

    incrementing the date


    Is there any way I can increment the day by one? Here is what I have at the moment:

    long dayLengthInMillis = (long)(24*60*60*1000);
    Date newDate = startDate.getTime() + dayLengthInMillis;
    However, I get a type mismatch error. (cannot convert from long to java.util.Date)

    Any suggestions, please? (This is for a loop in which I check the dates to see if they are weekdays, in case you want some context!)
  2. #2
  3. No Profile Picture
    Clueless llama
    Devshed Regular (2000 - 2499 posts)

    Join Date
    Feb 2001
    Location
    Lincoln, NE. USA
    Posts
    2,353
    Rep Power
    117
    How about:
    Code:
    long dayLengthInMillis = (long)(24*60*60*1000); 
    Date newDate = new Date(startDate.getTime() + dayLengthInMillis);
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2003
    Location
    Right Coast
    Posts
    25
    Rep Power
    0

    Look at Calendar and JulianCalendar


    Most methods to actually change the date exist in the Calendar class and its subclasses.

    J
  6. #4
  7. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2002
    Location
    England
    Posts
    8
    Rep Power
    0
    Thanks very much Nemi

    ahuimanu - thanks I am aware of the Calendar class, but I was sure there was a way of succeeding in the way I was attempting! I may actually switch over to the Calendar class later on
  8. #5
  9. No Profile Picture
    Clueless llama
    Devshed Regular (2000 - 2499 posts)

    Join Date
    Feb 2001
    Location
    Lincoln, NE. USA
    Posts
    2,353
    Rep Power
    117
    Just as an aside, if you are running that in any kind of long loop it will be very inefficient since you are making a lot of new temp objects.

IMN logo majestic logo threadwatch logo seochat tools logo