Increment timestamp by one day

Discussion in 'Java' started by sconeek@gmail.com, Mar 15, 2006.

  1. Guest

    hi all,
    how would i increment the timestamp by one day. i currently have,
    java.sql.Timestamp timestampTo = new
    java.sql.Timestamp(localDateTo.getTime());

    now i want to increment the timestamp by one day.
    any help please.
    thanks.
     
    , Mar 15, 2006
    #1
    1. Advertising

  2. JScoobyCed Guest

    wrote:
    > hi all,
    > how would i increment the timestamp by one day. i currently have,
    > java.sql.Timestamp timestampTo = new
    > java.sql.Timestamp(localDateTo.getTime());
    >
    > now i want to increment the timestamp by one day.
    > any help please.
    > thanks.
    >


    // 84600000 milliseconds in a day
    long oneDay = 1 * 24 * 60 * 60 * 1000;
    // to add to the timestamp
    timestampTo.setTime(timestampTo.getTime() + oneDay);

    --
    JSC
     
    JScoobyCed, Mar 15, 2006
    #2
    1. Advertising

  3. Oliver Wong Guest

    "JScoobyCed" <> wrote in message
    news:44179e7a$0$26215$...
    > wrote:
    >> hi all,
    >> how would i increment the timestamp by one day. i currently have,
    >> java.sql.Timestamp timestampTo = new
    >> java.sql.Timestamp(localDateTo.getTime());
    >>
    >> now i want to increment the timestamp by one day.
    >> any help please.
    >> thanks.
    >>

    >
    > // 84600000 milliseconds in a day
    > long oneDay = 1 * 24 * 60 * 60 * 1000;
    > // to add to the timestamp
    > timestampTo.setTime(timestampTo.getTime() + oneDay);


    Does the OP need to take into account leap seconds and perhaps
    non-gregorian calendars? If so, it might be safer (though more work) to
    parse the timestamp into a Date Object of the appropriate calendar type,
    increment the date by one day, and then convert back to a timestamp.

    - Oliver
     
    Oliver Wong, Mar 15, 2006
    #3
  4. jakeScript

    Joined:
    Jul 24, 2009
    Messages:
    1
    1 day == 86400000 not 84600000

    I know this is old but it is what came up when I searched for a one day timestamp.

    Here is a little JavaScript Function I wrote as well if it helps anyone.

    var changeDate = function(dayInterval) {
    var lengthOfInterval = dayInterval * 86400000;
    var currentDate = new Date().getTime();
    var newDate = currentDate + lengthOfInterval;
    return new Date(newDate).toGMTString();
    }

    Ex.

    var policy60Days = changeDate(60);

    If the current time is:
    Fri, 24 Jul 2009 17:47:08 GMT

    policy60Days is:
    Tue, 22 Sep 2009 17:47:08 GMT
     
    Last edited: Jul 24, 2009
    jakeScript, Jul 24, 2009
    #4
  5. sangeeta_lal

    Joined:
    Mar 3, 2012
    Messages:
    1
    nice way suggested on stack overflow

    java.sql.Timestamp ts = ...

    Calendar cal = Calendar.getInstance();
    cal.setTime(min_date);
    cal.add(Calendar.DAY_OF_WEEK, 1);
    java.sql.Timestamp new_date = new java.sql.Timestamp(cal.getTime().getTime());

    System.out.println("new date Cal="+new_date);
     
    sangeeta_lal, Mar 3, 2012
    #5
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Replies:
    104
    Views:
    11,024
    Jordan Abel
    Oct 28, 2005
  2. Replies:
    99
    Views:
    2,511
    eliza81
    Jun 11, 2010
  3. Andy
    Replies:
    1
    Views:
    718
  4. Alf P. Steinbach /Usenet
    Replies:
    0
    Views:
    899
    Alf P. Steinbach /Usenet
    May 22, 2011
  5. Peng Yu

    post increment or pre increment?

    Peng Yu, Nov 21, 2008, in forum: Perl Misc
    Replies:
    7
    Views:
    529
    Peter J. Holzer
    Nov 23, 2008
Loading...

Share This Page