Why TimeZone BUG 1 hour

Discussion in 'Plugin Development' started by Batman500, Jun 1, 2016.

Thread Status:
Not open for further replies.
  1. Offline

    Batman500

    View Line:
    System.out.println("sdf: " + sdf.format(hours));//ERROR HERE
    System.out.println("sdf2: " + sdf2.format(hours)); //BUT HERE, NO PROBLEM

    Code: (Computer Hours from Brazil)
    Code:
            SimpleDateFormat sdf = new SimpleDateFormat("HH-mm");
            SimpleDateFormat sdf2 = new SimpleDateFormat("HH-mm");
            TimeZone tz = TimeZone.getTimeZone("America/New_York");
            sdf.setTimeZone(tz);
            Date hoursCurrently = new Date(System.currentTimeMillis());
        
            Date hours = sdf2.parse(sdf2.format(new Date(System.currentTimeMillis())));
    
            System.out.println("sdf:  " + sdf.format(hoursCurrently));
            System.out.println("sdf:  " + sdf.format(hours));//ERROR HERE
            System.out.println("sdf2:  " + sdf2.format(hours)); //BUT HERE, NO PROBLEM
            System.out.println("sdf2:  " + sdf2.format(hoursCurrently));
    
    Out:
    sdf: 14-03
    sdf: 13-03
    sdf2: 15-03
    sdf2: 15-03
     
  2. Offline

    I Al Istannen

    @Batman500
    What is the problem?
    sdf2 has another timezone than sdf (if you don't live in New York). Why should they print out the same?
    What should they even print out?
     
  3. Offline

    Batman500

    @I Al Istannen When create a date from sdf2.parse(); and after format this date, this date reduce 1 hour. But when create a date direct with new Date() and after format, he works.
    I want know because it happens
     
  4. Offline

    I Al Istannen

    @Batman500
    Output for me:
    Code:
    sdf:  11-31
    sdf:  11-31
    sdf2:  17-31
    sdf2:  17-31
    What you would expect. Strange.
     
Thread Status:
Not open for further replies.

Share This Page