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

Discussion in 'Java' started by billdavidcn@gmail.com, Dec 27, 2006.

  1. Guest

    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?
     
    , Dec 27, 2006
    #1
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. z. f.
    Replies:
    0
    Views:
    714
    z. f.
    Feb 3, 2005
  2. Michal M
    Replies:
    7
    Views:
    817
    Andrew Thompson
    Aug 2, 2005
  3. Replies:
    3
    Views:
    5,221
    Bjorn Abelli
    Mar 30, 2006
  4. manzur
    Replies:
    5
    Views:
    510
    Chris Uppal
    Nov 9, 2006
  5. Mark Rafn
    Replies:
    17
    Views:
    1,424
    Andreas Leitgeb
    Jul 5, 2009
Loading...

Share This Page