C
Chris Murphy
I have some code that compares java.util.Date. The dates in
question have some of their fields blanked out so that the time
portion will be irrelevant to the comparison. I am not sure of the
technique being used to 'blank out' various fields in a
java.util.Date, but I do know that the technique gives different
results in the 1.4 and 1.5 JVMs.
The last line of output in the following code under 1.4 is
Got day: [Sat Sep 25 00:00:00 EST 2004]
Under 1.5 it is
Got day: [Sat Sep 25 12:00:00 EST 2004]
Is there any way I can get them to be the same under 1.4 and 1.5?
Preferably both having the time component of [00:00:00]?
==============================BEGIN CODE
public static void main( String[] args)
{
int dateInt = 25;
int monthInt = 8;
int yearInt = 2004;
GregorianCalendar day = new GregorianCalendar();
clearCalendar( day);
Err.pr( "date using: " + dateInt);
day.set( Calendar.DATE, dateInt);
Err.pr( "month using: " + monthInt);
day.set( Calendar.MONTH, monthInt);
Err.pr( "year using: " + yearInt);
day.set( Calendar.YEAR, yearInt);
//With 1.5 get [Sat Sep 25 12:00:00 EST 2004]
//With 1.4 got [Sat Sep 25 00:00:00 EST 2004]
Err.pr( "Got day: [" + day.getTime() + "]");
}
/**
* Clears everything from the calendar arg. The intention being
* that this method can be called before the invoking code goes
* on to set only the fields that it wants to set.
*/
public static void clearCalendar( Calendar calendar)
{
calendar.clear( Calendar.DAY_OF_WEEK_IN_MONTH);
calendar.clear( Calendar.DATE);
calendar.clear( Calendar.DAY_OF_MONTH);
calendar.clear( Calendar.HOUR);
calendar.clear( Calendar.HOUR_OF_DAY);
calendar.clear( Calendar.MINUTE);
calendar.clear( Calendar.SECOND);
calendar.clear( Calendar.MILLISECOND);
//attempting fix of 12:00 being introduced, but no help
calendar.clear( Calendar.PM);
}
==============================END CODE
Thanks for any help with this.
- Chris Murphy
question have some of their fields blanked out so that the time
portion will be irrelevant to the comparison. I am not sure of the
technique being used to 'blank out' various fields in a
java.util.Date, but I do know that the technique gives different
results in the 1.4 and 1.5 JVMs.
The last line of output in the following code under 1.4 is
Got day: [Sat Sep 25 00:00:00 EST 2004]
Under 1.5 it is
Got day: [Sat Sep 25 12:00:00 EST 2004]
Is there any way I can get them to be the same under 1.4 and 1.5?
Preferably both having the time component of [00:00:00]?
==============================BEGIN CODE
public static void main( String[] args)
{
int dateInt = 25;
int monthInt = 8;
int yearInt = 2004;
GregorianCalendar day = new GregorianCalendar();
clearCalendar( day);
Err.pr( "date using: " + dateInt);
day.set( Calendar.DATE, dateInt);
Err.pr( "month using: " + monthInt);
day.set( Calendar.MONTH, monthInt);
Err.pr( "year using: " + yearInt);
day.set( Calendar.YEAR, yearInt);
//With 1.5 get [Sat Sep 25 12:00:00 EST 2004]
//With 1.4 got [Sat Sep 25 00:00:00 EST 2004]
Err.pr( "Got day: [" + day.getTime() + "]");
}
/**
* Clears everything from the calendar arg. The intention being
* that this method can be called before the invoking code goes
* on to set only the fields that it wants to set.
*/
public static void clearCalendar( Calendar calendar)
{
calendar.clear( Calendar.DAY_OF_WEEK_IN_MONTH);
calendar.clear( Calendar.DATE);
calendar.clear( Calendar.DAY_OF_MONTH);
calendar.clear( Calendar.HOUR);
calendar.clear( Calendar.HOUR_OF_DAY);
calendar.clear( Calendar.MINUTE);
calendar.clear( Calendar.SECOND);
calendar.clear( Calendar.MILLISECOND);
//attempting fix of 12:00 being introduced, but no help
calendar.clear( Calendar.PM);
}
==============================END CODE
Thanks for any help with this.
- Chris Murphy