Results 1 to 2 of 2
  1. #1
    pburkel is offline Member
    Join Date
    Aug 2013
    Posts
    2
    Rep Power
    0

    Default issue setting Calendar value via setTimeInMilliseconds

    I am trying to create report start and end dates based on the current date. The following code produces the expected results:
    Calendar endDate = Calendar.getInstance();
    String cdate = DateTimeUtil.getStringFromDateWithoutT(endDate);
    endDate.set(Calendar.DAY_OF_WEEK, Calendar.SUNDAY);
    endDate.set(Calendar.HOUR_OF_DAY, 0);
    endDate.set(Calendar.MINUTE, 0);
    endDate.set(Calendar.SECOND, 0);
    endDate.set(Calendar.MILLISECOND, 0);

    Calendar reportStartDate = Calendar.getInstance();
    reportStartDate.setTimeInMillis(endDate.getTimeInM illis()
    - (1000L * 60 * 60 * 24 * 7 * 13));

    endDate is midnight of Sunday of the current week, and reportStartDate is midnight Sunday 13 weeks in the past.
    (today is Aug 20,2013, endDate is Aug18, 2013 00:00:00, and reportStartDate is May 19, 2013 00:00:00)

    When I try to generate a start date of 26 weeks in the past, by changing the '13' in the last statement above to '26', the resulting date is one hour earlier than expected (reportStartDate is Feb 16, 2013 23:00:00)

    What am I missing?

    NEVER MIND! Daylight Savings Time is the culprit.
    Last edited by pburkel; 08-21-2013 at 01:43 AM. Reason: Found reason for issue

  2. #2
    pburkel is offline Member
    Join Date
    Aug 2013
    Posts
    2
    Rep Power
    0

    Default Re: issue setting Calendar value via setTimeInMilliseconds

    Never mind...Daylight Savings Time is the culprit.

Similar Threads

  1. Calendar class issue
    By OlegKo in forum New To Java
    Replies: 3
    Last Post: 10-24-2010, 07:36 PM
  2. [SOLVED] Setting Calendar
    By VeasMKII in forum New To Java
    Replies: 4
    Last Post: 03-22-2009, 06:39 PM
  3. Calendar Pop-up issue
    By jeeva in forum JavaServer Pages (JSP) and JSTL
    Replies: 1
    Last Post: 01-29-2009, 02:09 AM
  4. Issue in calendar display
    By jeeva in forum New To Java
    Replies: 1
    Last Post: 01-14-2009, 02:19 PM
  5. Gregorian calendar issue
    By orchid in forum New To Java
    Replies: 1
    Last Post: 05-16-2007, 07:51 PM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •