Results 1 to 4 of 4
- 03-05-2012, 10:25 AM #1
Member
- Join Date
- Mar 2012
- Posts
- 2
- Rep Power
- 0
Calendar DAY_OF_YEAR problem in 1.6?
I have a problem using the GregorianCalendar:
First I create a GregorianCalendar instance and set the day of year with value -30. That's fine.
Afterwards I uses another GregorianCalendar doing the same but setting the day of year with value -1 and the result totally differs from what I expected. Instead of subtracting one day of the GregorianCalendar's current date it sets the calendar to 30th Dec one year before:
Where am I going wrong??Java Code:GregorianCalendar gc = new GregorianCalendar(); gc.add(GregorianCalendar.DAY_OF_YEAR, -30); Date startDate = gc.getTime(); System.out.println("startDate: " + startDate); // Sat Feb 04 10:01:21 CET 2012 Date endDate = new Date(); System.out.println("endDate: " + endDate); GregorianCalendar gc1 = new GregorianCalendar(); gc1.set(Calendar.DAY_OF_YEAR, -1); Date endDate = gc1.getTime(); System.out.println("endDate: " + endDate); // Thu Dec 30 10:01:24 CET 2011
- 03-05-2012, 10:30 AM #2
Re: Calendar DAY_OF_YEAR problem in 1.6?
add != set
dbWhy do they call it rush hour when nothing moves? - Robin Williams
- 03-05-2012, 10:45 AM #3
Member
- Join Date
- Mar 2012
- Posts
- 2
- Rep Power
- 0
Re: Calendar DAY_OF_YEAR problem in 1.6?
.gif)
Thank you!!!
Oha.. for the first date I did it well.
(Sometimes I miss the forest for the trees.)
What is the difference between add and set in this case? Is it because the value was negative? I can't see why the result is 64. (I would have an idea of what happened if the result would be 364. Then I could guess that Calendar calculates MAX_DAYS_OF_A_YEAR plus (myMinusValue) = 364.)
However, it works now. Thank you.
- 03-05-2012, 10:57 AM #4
Similar Threads
-
problem in calendar component
By irakli_dev in forum NetBeansReplies: 0Last Post: 12-09-2011, 11:08 AM -
Calendar mutator problem
By WimHaar in forum New To JavaReplies: 7Last Post: 01-04-2011, 12:25 PM -
Problem with compile Calendar
By santunez in forum New To JavaReplies: 1Last Post: 05-06-2010, 12:36 AM -
Calendar date problem
By groobelar in forum New To JavaReplies: 2Last Post: 01-17-2010, 03:47 AM -
Problem with calendar
By Felissa in forum Advanced JavaReplies: 2Last Post: 07-01-2007, 08:39 PM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks