getOffset question

A

Ahmad

I am not a Java programmer. Several years ago I got VisualCafe and tried to
write an applet. I put it on the a web site. I use it every so often and it
is working when I try it from my 2 machines. But my friend told me that it
is not working on his. So I try it on his and for sure I get the Java icon
and nothing else. In the Java console I get:

Using JRE version 1.4.2_03 Java HotSpot(TM) Client VM
User home directory = C:\Documents and Settings\user
Proxy Configuration: No proxy
..
..
java.lang.IllegalArgumentException
at sun.util.calendar.ZoneInfo.getOffset(Unknown Source)
at MyDate.initDate(MyDate.java:44)
at MyDate.<init>(MyDate.java:34)

the portion of code in MyDate.initDate is:

TimeZone TZ;
Today = new GregorianCalendar();
TZ = Today.getTimeZone();
Day = Today.get(Calendar.DAY_OF_MONTH);
Month = Today.get(Calendar.MONTH);
Year = Today.get(Calendar.YEAR);
TimeOffset = TZ.getOffset(Today.AD, Year, Month, Day, 0, 0);

What's wrong and why it is working on some machines?

Since I am not a Java programmer, I'll appreciate it if you post the right
code to work on all/most/more machines.
 
T

Thomas Hawtin

Ahmad said:
.
java.lang.IllegalArgumentException
at sun.util.calendar.ZoneInfo.getOffset(Unknown Source)
at MyDate.initDate(MyDate.java:44)
at MyDate.<init>(MyDate.java:34)

the portion of code in MyDate.initDate is:

TimeZone TZ;
Today = new GregorianCalendar();
TZ = Today.getTimeZone();
Day = Today.get(Calendar.DAY_OF_MONTH);
Month = Today.get(Calendar.MONTH);
Year = Today.get(Calendar.YEAR);
TimeOffset = TZ.getOffset(Today.AD, Year, Month, Day, 0, 0);

I guess it's because the day of week argument is illegal. It needs to be
between 1 (SUNDAY) and 7 (SATURDAY). I haven't used it, but wouldn't
TimeZone.getOffset(long) be easier?

(BTW, it'd be easier to read if used standard capitalisation conventions
and declared at first point of use.)

Tom Hawtin
 
A

Ahmad

Thomas Hawtin said:
I guess it's because the day of week argument is illegal. It needs to be
between 1 (SUNDAY) and 7 (SATURDAY). I haven't used it, but wouldn't
TimeZone.getOffset(long) be easier?

(BTW, it'd be easier to read if used standard capitalisation conventions
and declared at first point of use.)

Tom Hawtin

Thanks, Tom. I used getOffset(long) and it works. I wonder why it worked in
IE on some machines.

I agree with you about following the convention. I am not a Java programmer.
This is the first and only program I wrote in Java and I did not (and still
do not) know anything about Java programmer. I wrote this in 2001-2002 as an
exercise when our company was investigating use of Java.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,431
Messages
2,571,679
Members
48,796
Latest member
Greg L.

Latest Threads

Top