Foros Club Delphi

Foros Club Delphi (https://www.clubdelphi.com/foros/index.php)
-   Varios (https://www.clubdelphi.com/foros/forumdisplay.php?f=11)
-   -   Zona horaria (https://www.clubdelphi.com/foros/showthread.php?t=30660)

Genner 12-04-2006 18:28:54

Zona horaria
 
Buen dia,
estoy haciendo una aplicacion en la cual tengo q sincronizar la hora y fecha de un servidor de internet. Hasta aqui todo bien
Código Delphi [-]
Tidsntp.Host:='cronos.cenam.mx';
Tidsntp.SyncTime;
Tidsntp.DateTime;
label1.Caption:='Fecha actual '+DateToStr(Tidsntp.DateTime)+' Hora actual '+ TimeToStr(Tidsntp.DateTime);
la cosa es q aqui en Mexico hay horario de verano y el servidor me regresa una hora menos cuando, la explicacion q dan en cronos.cenam.mx es q la configuracion de la zona horaria de la pc debe ser (GMT-06:00) hora central EE.UU y CANADA.
La pregunta es, Hay alguna forma de controlar la zona horaria desde delphi??

Muchas gracias por su tiempo

Lepe 17-04-2006 14:22:20

Según acabo de ver es algo lioso el tema:
Cita:

Under legislation enacted in 1986, daylight saving time in the USA

begins at 2 a.m. on the first Sunday of April and
ends at 2 a.m. on the last Sunday of October

In most of the countries of western Europe, including the countries that are members of the EEC, daylight saving time:

begins at 1 a.m. GMT on the last Sunday of March and
ends at 1 a.m. GMT on the last Sunday of October

Daylight Saving Time - for the U.S. and its territories - is not observed in Hawaii, American Samoa, Guam, Puerto Rico, the Virgin Islands, the Eastern Time Zone portion of the State of Indiana, and by most of Arizona (with the exception of the Navajo Indian Reservation in Arizona).

In many other countries around the world, daylight saving time lasts from March 30th to October 26th.


This article from the link: http://www.timechange.com/dls/dls1.html
Extraido de http://www.thanhda.com/community/ind...;threadid=2547


Con el siguiente código sacas la fecha según los americanos, quizás tengas que adaptarla.
Código Delphi [-]

procedure TForm1.Button1Click(Sender: TObject);
var
  tzInfo: TTimeZoneInformation;
  StandardDate: TDate;
  DayLightDate: TDate;

begin
  GetTimeZoneInformation(tzInfo);

  DaylightDate := EncodeDate(
    yearof(date),
    tzInfo.DaylightDate.wMonth,
    tzInfo.DaylightDate.wDay
  );
  ShowMessage(FormatDateTime('dd-mm-yyyy',DayLightDate));



  StandardDate := EncodeDate(
    yearof(date),
    tzInfo.StandardDate.wMonth,
    tzInfo.StandardDate.wDay
  );
  ShowMessage(FormatDateTime('dd-mm-yyyy',StandardDate));

end;

Para hallar el primer domingo de un mes determinado uso esto:
Código Delphi [-]
          // si la fecha de aviso era un domingo,
          // averiguamos el primer domingo del mes de la Fecha
          DecodeDayOfWeekInMonth(FechaAviso, y, m, an, d);
          NotaActualizada := EncodeDayOfWeekInMonth(YearOf(Fecha),
            MonthOf(Fecha),
            1, // aqui el primero, si queremos el último domingo, poner un 4 o 5 (depende del mes)
            d); // dia de la semana, en este caso 7 porque es un domingo lo que buscamos
          RecodeTime(NotaActualizada, HourOf(FechaAviso),
            MinuteOf(FechaAviso),
            0, 0);

Saludos


La franja horaria es GMT +2. Ahora son las 00:02:33.

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Traducción al castellano por el equipo de moderadores del Club Delphi