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

 
 
Herramientas Buscar en Tema Desplegado
  #8  
Antiguo 07-12-2024
mqm mqm is offline
Miembro
 
Registrado: nov 2006
Posts: 63
Poder: 20
mqm Va por buen camino
prueba con este: A mi me funciona correctamente en delphi 7
Código:
unit Unit2;

interface

uses
  Windows, SysUtils, IdHTTP, IdSSLOpenSSL, DateUtils;

function LeeFechaHoraInternet: string;

implementation


function GetTimeZoneOffset: TDateTime;
var
  TZInfo: TTimeZoneInformation;
  Bias: Integer;
begin
  case GetTimeZoneInformation(TZInfo) of
    TIME_ZONE_ID_STANDARD, TIME_ZONE_ID_DAYLIGHT:
      Bias := TZInfo.Bias + TZInfo.DaylightBias; // Ajuste según horario de verano
    else
      Bias := 0; // Si no se puede determinar la zona horaria, se asume UTC
  end;
  Result := Bias / MinsPerDay; // Convertir minutos a días
end;

function LeeFechaHoraInternet: string;
var
  Http: TIdHTTP;
  SSLHandler: TIdSSLIOHandlerSocketOpenSSL;
  Respuesta: string;
  UnixTicks: Int64;
  FechaHoraUTC, FechaHoraLocal: TDateTime;
  TimeZoneOffset: TDateTime;
begin
  Result := FormatDateTime('yyyy-mm-dd"T"hh:nn:ss"Z"', Now); // Valor predeterminado
  Http := TIdHTTP.Create(nil);
  SSLHandler := TIdSSLIOHandlerSocketOpenSSL.Create(nil);
  try
    SSLHandler.SSLOptions.Method := sslvTLSv1_2;  // Usar TLS 1.2
    SSLHandler.SSLOptions.SSLVersions := [sslvTLSv1_2];
    SSLHandler.SSLOptions.Mode := sslmClient;    // Modo cliente
    // Configurar cliente con este manejador SSL
//    IdHTTP1.IOHandler := SSLHandler;
//    IdHTTP1.Request.UserAgent := 'Mozilla/5.0';
    // Realiza la conexión HTTP/HTTPS
//    IdHTTP1.Get('https://yourserver.com');
    Http.IOHandler := SSLHandler;
    Http.Request.Accept := 'application/json';
    Http.Request.UserAgent := 'Mozilla/5.0 (compatible; Delphi)';
    try
      // Realizar la solicitud HTTP
      Respuesta := Http.Get('https://www2.roa.es/cgi-bin/horautc');
//     Respuesta := Http.Get('https://www.google.com');

      // Convertir la respuesta (ticks Unix) a DateTime
      UnixTicks := StrToInt64(Trim(Respuesta));
      FechaHoraUTC := UnixDateDelta + (UnixTicks div SecsPerDay) + (UnixTicks mod SecsPerDay) / SecsPerDay;

      // Obtener el desfase horario
      TimeZoneOffset := GetTimeZoneOffset;
      FechaHoraLocal := FechaHoraUTC - TimeZoneOffset;

      // Devolver la fecha y hora en formato ISO 8601
      Result := FormatDateTime('yyyy-mm-dd"T"hh:nn:ss"Z"', FechaHoraLocal);
    except
      on E: Exception do
        // En caso de error, devolver la hora actual
        result := E.Message;
//        Result := FormatDateTime('yyyy-mm-dd"T"hh:nn:ss"Z"', Now);
    end;
  finally
    Http.Free;
    SSLHandler.Free;
  end;
end;
end.
Responder Con Cita
 



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
TimeStamp Willo MySQL 4 22-03-2016 21:15:00
Consulta TimeStamp Jose Roman SQL 2 06-09-2012 04:03:11
TimeStamp = TimeStamp me da error Chogo Firebird e Interbase 7 16-03-2011 04:13:38
TIMESTAMP en restriccion Cañones SQL 6 28-08-2007 23:19:27
Timestamp y bde 5.2 Toni Firebird e Interbase 2 27-05-2003 09:26:33


La franja horaria es GMT +2. Ahora son las 14:54:13.


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