Skip to Main Content

Java SE (Java Platform, Standard Edition)

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

java.lang.IllegalArgumentException: HOUR_OF_DAY

843806Apr 8 2009 — edited Apr 8 2009
Hi,
I am trying to convert the time of my timezone to another time zone. Ans I have tried the following program and i got the exception. Kindly let me know if i am doing anything wrong.
import java.util.Calendar;
import java.util.GregorianCalendar;

public class GMTDateConversionTest {

	 public static void main(String[] args){

	        Calendar c = GregorianCalendar.getInstance();
	        c.setLenient(false);
	        c.set(2, 2);
	        c.set(5, 7);
	        c.set(1, 2009);
	        c.set(11,19);
	        c.set(12,0);
	        c.set(13, 0);
	        c.add(5, 1);
	        c.set(11, 2);

	        System.out.println(c.getTime());  // Exception occurs here when i try to print the c.gettime() ;
	    }
}
Exception in thread "main" java.lang.IllegalArgumentException: HOUR_OF_DAY
at java.util.GregorianCalendar.computeTime(Unknown Source)
at java.util.Calendar.updateTime(Unknown Source)
at java.util.Calendar.getTimeInMillis(Unknown Source)
at java.util.Calendar.getTime(Unknown Source)
at Use.GMTDateConversionTest.main(GMTDateConversionTest.java:34)
I am using Sun JDK 1.5.0_15

The issue occurs when my system time zone is "(GMT-07.00) Mountain Time (US & Canada)". The issue will not occurs when my time zone is "(GMT+05:30) Calcutta, Chennai, Mumbai, New Delhi"

Thanks In advance,
SelvaKumar S
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on May 6 2009
Added on Apr 8 2009
1 comment
4,776 views