Results 1 to 2 of 2
  1. #1
    pborgen is offline Member
    Join Date
    Oct 2014
    Posts
    1
    Rep Power
    0

    Default Java Time zone transition period from EDT to EST

    Problem statement: Convert "2014-11-02 01:00:15 EST" to GMT.

    This seems easy enough. But why is the below code giving the wrong answer?

    Background:

    * EDT aka GMT-4
    * EST aka GMT-5
    * 2014-11-02 01:00:15 EST == 2014-11-02 06:00:15 GMT
    * If I user the commented out date string it works!!!
    * EDT(until Nov 2, 2014 at 2am) -> at 2am we go to 1am EST
    * If I use the below commented out from string it work!!! But these are equal (2014-11-02 01:00:15 GMT-05:00 and "2014-11-02 01:00:15 EST)

    Code Example:

    ZoneId gmt = ZoneId.of("GMT");
    //String from = "2014-11-02 01:00:15 GMT-05:00";
    String from = "2014-11-02 01:00:15 EST";

    final DateTimeFormatter dateTimeFormatterone = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss z");
    ZnedDateTime zonedDateTime = ZonedDateTime.parse(from, dateTimeFormatterone);
    ZonedDateTime gmtzonedDateTime = zonedDateTime.withZoneSameInstant(gmt);
    String result = gmtzonedDateTime.format(dateTimeFormatterone);

    This is what the outcome is.

    result == "2014-11-02 05:00:15 GMT"

    Shouldn't it be
    result == "2014-11-02 06:00:15 GMT"

    Any help would be great. I am thinking this is a bug in Java. But I am also think I am making a error somewhere.

    Thanks
    Paul

  2. #2
    jim829 is online now Senior Member
    Join Date
    Jan 2013
    Location
    Northern Virginia, United States
    Posts
    4,039
    Rep Power
    6

    Default Re: Java Time zone transition period from EDT to EST

    I am uncertain what is going on here since all of this is part of Java 1.8. But until I take the time to check out all the related
    methods and understand how it is supposed to work, I am hesitant to say it is a bug.

    Regards,
    Jim
    The JavaTM Tutorials | SSCCE | Java Naming Conventions
    Poor planning on your part does not constitute an emergency on my part

Similar Threads

  1. Replies: 5
    Last Post: 02-29-2012, 11:07 AM
  2. calculate time diff for particular time period
    By baktha.thalapathy in forum New To Java
    Replies: 2
    Last Post: 05-24-2010, 05:10 PM
  3. Replies: 0
    Last Post: 02-22-2010, 02:44 AM
  4. Time zone stamp
    By ddscart in forum New To Java
    Replies: 1
    Last Post: 08-02-2009, 09:41 PM
  5. time Zone
    By mohammedsiddig in forum JavaServer Pages (JSP) and JSTL
    Replies: 0
    Last Post: 09-07-2008, 04:38 PM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •