S
Silvia
Hi,
I habe a problem with setting HOUR_OF_DAY of my Calendar object to 0.
My method today() should give me a Date object containing today's date
in a configured timezone at 0:00 o'clock. Here is the code:
public Calendar getCalendarOfTimeZone() {
TimeZone timezone =
TimeZone.getTimeZone( Config.getProperty( "timezone" ) );
Calendar cal = Calendar.getInstance( timezone );
System.out.println( "### system time: " + cal.getTime() );
int offset = timezone.getOffset( cal.getTimeInMillis() );
cal.add( Calendar.MILLISECOND, offset );
System.out.println( "### adjusted time: " + cal.getTime() );
return cal;
}
public Date today() {
Calendar cal = getCalendarOfTimeZone();
System.out.println( "### time 1 : " + cal.getTime() );
cal.set( Calendar.HOUR_OF_DAY, 0 );
System.out.println( "### time 1 : " + cal.getTime() );
cal.clear( Calendar.HOUR_OF_DAY );
System.out.println( "### time 2 : " + cal.getTime() );
cal.clear( Calendar.MINUTE );
System.out.println( "### time 3 : " + cal.getTime() );
cal.clear( Calendar.SECOND );
System.out.println( "### time 4 : " + cal.getTime() );
return cal.getTime();
}
The output is:
### system time: Thu Jun 17 13:25:25 CEST 2004
### adjusted time: Thu Jun 17 06:25:25 CEST 2004
### time 0 : Thu Jun 17 06:25:25 CEST 2004
### time 1 : Wed Jun 16 09:25:25 CEST 2004
### time 2 : Wed Jun 16 09:25:25 CEST 2004
### time 3 : Wed Jun 16 09:00:25 CEST 2004
### time 4 : Wed Jun 16 09:00:00 CEST 2004
So, the adjusted time is correct (7 hours less than system time), but
while minutes and seconds are correctly set to 0, the hours are set to
the previous day at 09 hours. Why ???
Thanks for any help )
Silvia
I habe a problem with setting HOUR_OF_DAY of my Calendar object to 0.
My method today() should give me a Date object containing today's date
in a configured timezone at 0:00 o'clock. Here is the code:
public Calendar getCalendarOfTimeZone() {
TimeZone timezone =
TimeZone.getTimeZone( Config.getProperty( "timezone" ) );
Calendar cal = Calendar.getInstance( timezone );
System.out.println( "### system time: " + cal.getTime() );
int offset = timezone.getOffset( cal.getTimeInMillis() );
cal.add( Calendar.MILLISECOND, offset );
System.out.println( "### adjusted time: " + cal.getTime() );
return cal;
}
public Date today() {
Calendar cal = getCalendarOfTimeZone();
System.out.println( "### time 1 : " + cal.getTime() );
cal.set( Calendar.HOUR_OF_DAY, 0 );
System.out.println( "### time 1 : " + cal.getTime() );
cal.clear( Calendar.HOUR_OF_DAY );
System.out.println( "### time 2 : " + cal.getTime() );
cal.clear( Calendar.MINUTE );
System.out.println( "### time 3 : " + cal.getTime() );
cal.clear( Calendar.SECOND );
System.out.println( "### time 4 : " + cal.getTime() );
return cal.getTime();
}
The output is:
### system time: Thu Jun 17 13:25:25 CEST 2004
### adjusted time: Thu Jun 17 06:25:25 CEST 2004
### time 0 : Thu Jun 17 06:25:25 CEST 2004
### time 1 : Wed Jun 16 09:25:25 CEST 2004
### time 2 : Wed Jun 16 09:25:25 CEST 2004
### time 3 : Wed Jun 16 09:00:25 CEST 2004
### time 4 : Wed Jun 16 09:00:00 CEST 2004
So, the adjusted time is correct (7 hours less than system time), but
while minutes and seconds are correctly set to 0, the hours are set to
the previous day at 09 hours. Why ???
Thanks for any help )
Silvia