A problem about getting different time information with jdk1.4 and jdk1.5

B

billdavidcn

I find a strange problem on my HP-UX. I get different time and timezone
information with jdk1.4 and jdk1.5. The following is my program:

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Calendar;
import java.util.GregorianCalendar;
import java.util.TimeZone;

public class Test {
public String getTimeStr(Date date){
SimpleDateFormat s = new SimpleDateFormat("yyyyMMddHHmmss");
return s.format(date);
}

public static void main(String[] args) {
Test t = new Test();
Calendar calendar = new GregorianCalendar();

String s1 = t.getTimeStr(calendar.getTime());
System.out.println(s1);

String s2 = t.getTimeStr(new Date());
System.out.println(s2);

String s3 = TimeZone.getDefault().getDisplayName();
System.out.println(s3);
}
}

When I run it with jdk1.4, I get:
$ ../java1.4/bin/java Test
20061227161314
20061227161314
GMT+08:00

When I run it with jdk1.5, I get:
$ ../java1.5/bin/java Test
20061227081410
20061227081410
¸ñÁÖÍþÖÎʱ¼ä--->ie. GMT+00:00

There is a difference of 8 hours between two results. While the system
time I get on sh with `date` is same as what I have gotten with jdk1.4.
Is there any configuration in jdk that may impact the result?
 

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
473,982
Messages
2,570,185
Members
46,736
Latest member
AdolphBig6

Latest Threads

Top