Delphi 2010 - Seattle - TFile.
Delphi 2010 - Seattle - TFile.GetLastWriteTimeUtc returns wrong (-1 hour), for a file timestamp set with TFile.SetLastWriteTimeUtc. Looks like caused by daylight savings offset.
Sample below:
var
fileName: String;
fileTimeStamp: TDateTime;
begin
fileName := 'D:\testdate.txt';
//create the file
if not TFile.Exists(fileName) then
TFile.WriteAllText(fileName, ' ');
fileTimeStamp := EncodeDateTime(2015, 8, 22, 14, 26, 22, 0);
ShowMessage('Set ' + DateTimeToStr(fileTimeStamp)); //shows 2015-08-22 14:26:22, correct
TFile.SetLastWriteTimeUtc(fileName, fileTimeStamp);
ShowMessage('Get ' + DateTimeToStr(TFile.GetLastWriteTimeUtc(fileName))); //shows 2015-08-22 13:26:22, wrong -1 hour
end;
Sample below:
var
fileName: String;
fileTimeStamp: TDateTime;
begin
fileName := 'D:\testdate.txt';
//create the file
if not TFile.Exists(fileName) then
TFile.WriteAllText(fileName, ' ');
fileTimeStamp := EncodeDateTime(2015, 8, 22, 14, 26, 22, 0);
ShowMessage('Set ' + DateTimeToStr(fileTimeStamp)); //shows 2015-08-22 14:26:22, correct
TFile.SetLastWriteTimeUtc(fileName, fileTimeStamp);
ShowMessage('Get ' + DateTimeToStr(TFile.GetLastWriteTimeUtc(fileName))); //shows 2015-08-22 13:26:22, wrong -1 hour
end;
Comments
Post a Comment