1 Reply Latest reply: May 21, 2008 1:54 AM by 807591 RSS

    SimpleDateFormat: weird behaviors of format() and parse()

    807591
      Hi,
      I wanted to convert a given date to another date with a different timezone. I wrote the code below:
      SimpleDateFormat fmt = new SimpleDateFormat("MM/dd/yyyy");
      fmt.setTimeZone(TimeZone.getTimeZone(tz));
      givenDate.toString() // output is: 2008-05-18 09:38:06.349
      Format:
      fmt.format(givenDate); // output is: 05/17/2008
      Parse:
      fmt.parse("05/18/2008 09:38:06.349"); // output is: Sun May 18 13:00:00 GMT+06:00 2008
      I dont understand why would the logically reverse operation would change the output and show wrong result.

      All I want to do is just change the date to a different timezone. How can I get out of this jdk date/time mess?