GMT returns -0306 instead of -0300, what is the reason?

Asked

Viewed 384 times

11

Locale ptBR = new Locale("pt", "BR");
SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yyy", ptBR);
SimpleDateFormat iso = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.sssZ");
GregorianCalendar calendar = new GregorianCalendar(ptBR);
String data = "31/12/1900";
calendar.setTime(sdf.parse(data));
iso.setTimeZone(calendar.getTimeZone());
System.out.println(iso.format(calendar.getTime()));

Exit: 1900-12-31T00:00:00.000-0306

Can anyone explain to me why the GMT returns -0306 instead of -0300?

  • Go see your computer created a spindle just for him :) Or you gave him cachaça :) I have no idea if this can happen in "normal conditions". I did not reproduce: http://ideone.com/KLgcdr

  • 1

    I reproduced, it may have something to do with the temporal discontinuity, something similar to that

  • Daylight saving time? o. õ

  • Try with a recent date. If it’s because of Leap-Seconds the difference is to disappear

  • 2

    Jon Skeet to the Rescue! http://stackoverflow.com/a/6841479/916193

  • @Bacco then this is the Jon Skeet who spoke on chat kkkk

  • @Diegofelipe Here’s a summary of his skills http://meta.stackexchange.com/questions/9134

  • What is the return of calendar.getTimeZone()?

  • @bfavaretto the return is Mon Dec 31 00:00:00 BRT 1900

  • @Bacco with recent dates does not happen.

  • I found that the problem happens until "12/31/1913", after that normalizes.

  • Related: http://www.timeanddate.com/time/change/brazil/recife?year=1913 and http://www.timeanddate.com/time/change/brazil/salvador?year=1913 Except that in other cities of Brazil this does not happen, except that the salvador adjustment was different from the reef. It’s hard to understand...

  • 2

    @Math I think I got it, see answer (my Skeet day!!!).

Show 8 more comments

2 answers

14


Until 1914, Brazil used the LMT (Local Mean Time) as a time reference. Since that year, it has adopted different time zones, with differences in round hours in relation to UTC. The LMT is based on longitude, so there were time fractions differences from one location to another.

With the regulation of official time zones by decree in 1913 (current since 1/1/1914), the small differences between the localities were normalized, as shown in the table in this decree:

inserir a descrição da imagem aqui

Note that in 1/1/1914 the time of São Paulo should be corrected in 6m35s. I believe that is the difference that your code is showing.

  • Doing so: System.out.println(new Date("01/01/1914")); I have it: Thu Jan 01 00:06:28 BRT 1914, move to 02/01/1914 he gets it right: Fri Jan 02 00:00:00 BRT 1914

  • Yes, the decree speaks in 6m35s, but in fact the timeanddate.com (choosing period 1900-1924) indicates 6m28s. I do not know the reason for this difference.

  • Where did you get this image? It’s written "slow down", Argh! Outside the "Goyaz", "Cuyabá"...

  • In 1913 it was written :) The image is a screenshot of the current version of the decree on the government website (therefore the strike, most of what is there has already been overcome by later legislation).

  • I’ll be sure to ask on [Portuguese.se], rs..

-3

Hi @Luan, the code below is for you?

Locale ptBR = new Locale("pt", "BR");
SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yyy", ptBR);
SimpleDateFormat iso = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.sssX");
GregorianCalendar calendar = new GregorianCalendar(ptBR);
String data = "31/12/1900";
calendar.setTime(sdf.parse(data));
iso.setTimeZone(calendar.getTimeZone());
System.out.println(iso.format(calendar.getTime()));
  • 1

    You just flipped the last digits...

  • 1

    I don’t want an option to remove the last digits, I want to understand why.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.