Foros Club Delphi

Foros Club Delphi (https://www.clubdelphi.com/foros/index.php)
-   Varios (https://www.clubdelphi.com/foros/forumdisplay.php?f=11)
-   -   Cambiar fecha y hora (https://www.clubdelphi.com/foros/showthread.php?t=89766)

Ramsay 03-02-2016 00:07:01

Cambiar fecha y hora
 
Hola , estoy tratando de cambiar la fecha y hora de un archivo con este codigo.

Código Delphi [-]
const
  FILE_WRITE_ATTRIBUTES = $0100;

procedure SetFileCreationTime(const FileName: string; const DateTime: TDateTime);
var
  Handle: THandle;
  SystemTime: TSystemTime;
  FileTime: TFileTime;
begin
  Handle := CreateFile(PChar(FileName), FILE_WRITE_ATTRIBUTES,
    FILE_SHARE_READ or FILE_SHARE_WRITE, nil, OPEN_EXISTING,
    FILE_ATTRIBUTE_NORMAL, 0);
  if Handle=INVALID_HANDLE_VALUE then
    RaiseLastOSError;
  try
    DateTimeToSystemTime(DateTime, SystemTime);
    if not SystemTimeToFileTime(SystemTime, FileTime) then
      RaiseLastOSError;
    if not SetFileTime(Handle, @FileTime, nil, nil) then
      RaiseLastOSError;
  finally
    CloseHandle(Handle);
  end;
end;

procedure TForm1.btntestClick(Sender: TObject);
var
  DateTime: TDateTime;
begin
  DateTime := StrToDateTime('6/7/1998 14:00:20');
  SetFileCreationTime(paramstr(0), DateTime);
end;

El tema es que la fecha la cambia bien , pero la hora siempre aparece como 3 horas antes o 5 despues.

¿ Cual es el problema ?

Casimiro Noteví 03-02-2016 10:27:49

¿En qué país estás?

Ramsay 03-02-2016 15:31:02

Soy de Chile.

Casimiro Noteví 03-02-2016 17:19:21

3 horas de diferencia es lo que tenéis con UTC/GMC
Seguramente al usar esta línea:
Código Delphi [-]
DateTimeToSystemTime(DateTime,SystemTime);
Estás asignando la hora del sistema, y no la local.

PD: Sin embargo, tu IP y tu servidor de internet son ambos de Argentina.


La franja horaria es GMT +2. Ahora son las 23:56:10.

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