Club Delphi  
    Paypal   FTP   CCD     Buscar   Trucos   Trabajo   Foros

Retroceder   Foros Club Delphi > Proyecto SIF/Veri*Factu/Ley Antifraude > Envío de registros y sus respuestas
Registrarse FAQ Miembros Calendario Guía de estilo Temas de Hoy

Respuesta
 
Herramientas Buscar en Tema Desplegado
  #1  
Antiguo 05-11-2024
mqm mqm is offline
Miembro
 
Registrado: nov 2006
Posts: 63
Poder: 20
mqm Va por buen camino
Aqui teneis en codigo en delphi 11.

Código Delphi [-]
unit VerificaFecha;
interface

uses
  IdUDPClient, IdGlobal, SysUtils, DateUtils;

function GetNetworkTime: TDateTime;

implementation

function SwapEndianness(Value: UInt32): UInt32;
begin
  Result := ((Value and $000000FF) shl 24) or
            ((Value and $0000FF00) shl 8) or
            ((Value and $00FF0000) shr 8) or
            ((Value and $FF000000) shr 24);
end;

function GetNetworkTime: TDateTime;
const
  NTP_SERVER = 'time.windows.com';
  NTP_PORT = 123;
  NTP_PACKET_SIZE = 48;
  NTP_TIMESTAMP_OFFSET = 2208988800; // Seconds between 1900 and 1970
  SERVER_REPLY_TIME = 40; // Offset to "Transmit Timestamp"
var
  UDPClient: TIdUDPClient;
  NTPData: TIdBytes;
  Seconds, Fraction: UInt32;
  UnixTime: UInt64;
begin
  UDPClient := TIdUDPClient.Create(nil);
  try
    UDPClient.Host := NTP_SERVER;
    UDPClient.Port := NTP_PORT;
    UDPClient.BufferSize := NTP_PACKET_SIZE;

    SetLength(NTPData, NTP_PACKET_SIZE);
    FillChar(NTPData[0], NTP_PACKET_SIZE, 0);

    // Set LI, VN, Mode
    NTPData[0] := $1B;

    // Send request
    UDPClient.Connect;
    UDPClient.SendBuffer(NTPData);

    // Receive response
    UDPClient.ReceiveTimeout := 3000;
    UDPClient.ReceiveBuffer(NTPData);

    // Extract timestamp
    Seconds := SwapEndianness(PCardinal(@NTPData[SERVER_REPLY_TIME])^);
    Fraction := SwapEndianness(PCardinal(@NTPData[SERVER_REPLY_TIME + 4])^);

    UnixTime := Seconds - NTP_TIMESTAMP_OFFSET;
    Result := UnixDateDelta + UnixTime / SecsPerDay;
    Result := Result + (Fraction / High(UInt32) / SecsPerDay);

    // Convert to local time
    Result := TTimeZone.Local.ToLocalTime(Result);
  finally
    UDPClient.Free;
  end;
end;

end.

Y ejemplo de llamada :
procedure TForm3.Button1Click(Sender: TObject);
var
  NetworkTime: TDateTime;
begin
  try
    NetworkTime := GetNetworkTime;
    ShowMessage('La hora de red es: ' + DateTimeToStr(NetworkTime));
  except
    on E: Exception do
      ShowMessage('Error al obtener la hora de red: ' + E.Message);
  end;
end;

Última edición por Neftali [Germán.Estévez] fecha: 05-11-2024 a las 12:13:46. Razón: Añadir TAG's al código
Responder Con Cita
  #2  
Antiguo 05-11-2024
Avatar de Neftali [Germán.Estévez]
Neftali [Germán.Estévez] Neftali [Germán.Estévez] is online now
[becario]
 
Registrado: jul 2004
Ubicación: Barcelona - España
Posts: 19.441
Poder: 10
Neftali [Germán.Estévez] Es un diamante en brutoNeftali [Germán.Estévez] Es un diamante en brutoNeftali [Germán.Estévez] Es un diamante en bruto
Cita:
Empezado por mqm Ver Mensaje
Aqui teneis en codigo en delphi 11.

Por favor, añadid TAG's cuando pongáis código en los mensajes.
Para los nuevos en los foros, la recomendación es leer la Guía de estilo de los foros.
__________________
Germán Estévez => Web/Blog
Guía de estilo, Guía alternativa
Utiliza TAG's en tus mensajes.
Contactar con el Clubdelphi

P.D: Más tiempo dedicado a la pregunta=Mejores respuestas.
Responder Con Cita
Respuesta



Normas de Publicación
no Puedes crear nuevos temas
no Puedes responder a temas
no Puedes adjuntar archivos
no Puedes editar tus mensajes

El código vB está habilitado
Las caritas están habilitado
Código [IMG] está habilitado
Código HTML está deshabilitado
Saltar a Foro

Temas Similares
Tema Autor Foro Respuestas Último mensaje
Como le resto una hora a la fecha y hora en sql server uper MS SQL Server 3 12-10-2015 20:41:49
Agrupar por fecha, teniendo en el campo fecha y hora El_Raso Firebird e Interbase 3 18-03-2010 22:05:19
obtener solo la fecha en formato fecha y sin hora BlueSteel SQL 14 09-05-2008 16:42:19
formato fecha y hora a solo Fecha ozegarra Firebird e Interbase 6 22-02-2008 18:43:34
Extraccion fecha de un campo fecha y hora matti Firebird e Interbase 3 26-04-2007 19:48:11


La franja horaria es GMT +2. Ahora son las 13:42:04.


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