- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
function DateTimeToFileTime(FileTime: TDateTime): TFileTime;
var
LocalFileTime, Ft: TFileTime;
SystemTime: TSystemTime;
begin
Result.dwLowDateTime := 0;
Result.dwHighDateTime := 0;
DateTimeToSystemTime(FileTime, SystemTime);
SystemTimeToFileTime(SystemTime, LocalFileTime);
LocalFileTimeToFileTime(LocalFileTime, Ft);
Result := Ft;
end;
function ExtractShortDate(ATimeIn: TDateTime): string;
// Convert DateTime to short date string
begin
Result := FormatDateTime('mm/dd/yyyy', ATimeIn);
end;
function ExtractTime(ATimeIn: TDateTime): string;
// Convert DateTime to am/pm time string
begin
Result := FormatDateTime('hh:mm AM/PM', ATimeIn);
end;
function GetDateFileModified(AFileName: string): string;
// Return the file modified date as a string in local time
var
SR: TSearchRec;
UTCTime: Windows.TFileTime;
GMTST: Windows.TSystemTime;
LocalST: Windows.TSystemTime;
ModifyDT: TDateTime;
TZ: Windows._TIME_ZONE_INFORMATION;
begin
Result := '';
if FindFirst(AFileName, faAnyFile, SR) = 0 then
begin
UTCTime := SR.FindData.ftLastWriteTime;
if FileTimeToSystemTime(UTCTime, GMTST) then
begin
// Get Timezone Information
if GetTimeZoneInformation(TZ) <> 0 then
if SystemTimeToTzSpecificLocalTime(@TZ, GMTST, LocalST) then
begin
ModifyDT := SystemTimeToDateTime(LocalST);
Result := ExtractShortDate(ModifyDT) + ' ' + ExtractTime(ModifyDT);
end
else
begin
TaskMessageDlg('Unable To Convert Time', 'Unable to convert SystemTime To LocalTime',
mtInformation, [mbOk], 0);
Result := '';
exit;
end;
end
else
begin
TaskMessageDlg('Unable To Convert Time', 'Unable to convert FileTime To SystemTime',
mtInformation, [mbOk], 0);
Result := '';
exit;
end;
end
else
TaskMessageDlg('File Not Found', ExtractFileName(AFileName) + ' does not exist.',
mtInformation, [mbOk], 0);
FindClose(SR);
end;
发布的原始代码未返回正确的时间。原始代码已替换为工作代码,以便其他人可能会发现这很有用。
更新:由于所有协助,代码现在提供了正确的时间。
最佳答案
MSDN 文档中针对 FileTimeToLocalFileTime 突出显示了该问题:
FileTimeToLocalFileTime uses the current settings for the time zone and daylight saving time. Therefore, if it is daylight saving time, this function will take daylight saving time into account, even if the time you are converting is in standard time. You can use the following sequence of functions as an alternative.
FileTimeToSystemTime / SystemTimeToTzSpecificLocalTime / SystemTimeToFileTime
每当您在夏令时更改后查看更改之前创建的文件时,您都需要使用指定的三个函数(但是当您和文件创建都位于文件的同一侧时,此方法当然也适用)夏令时更改)。
关于delphi - GetDateFileModified 夏令时,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13178785/
function DateTimeToFileTime(FileTime: TDateTime): TFileTime; var LocalFileTime, Ft: TFileTime; S
我是一名优秀的程序员,十分优秀!