unter Windows kenne ich einen Weg (nicht sehr schön geht aber), Unter Unix leider nicht!
Hat jemand einen besseren Weg und/oder einen Weg für Unix, etc?
Code: Alles auswählen
function FormatGMTDateTime(const DTFormat: string; const dt: TDateTime; GMTFormat: string = ''): string;
function LastSunday(): TDateTime;
begin
result := EncodeDate(YearOf(dt), MonthOf(dt), DaysInMonth(dt));
while DayOfTheWeek(result)<>DaySunday do result := result-1;
end;
var
h: integer;
TZInfo: TTimeZoneInformation;
fs: TFormatSettings;
begin
GetLocaleFormatSettings(GB_LCID, fs);
GetTimeZoneInformation(TZInfo);
h := (TZInfo.Bias + TZInfo.StandardBias) DIV 60;
case MonthOf(dt) of
4,5,6,7,8,9 : dec(h);
3 : if dt>=LastSunday() then dec(h);
10 : if dt<LastSunday() then dec(h);
end;
if GMTFormat='' then
result := FormatDateTime(DTFormat, IncHour(dt, h), fs)
else
result := FormatDateTime(DTFormat, IncHour(dt,h), fs) +
IIF(GMTFormat[1]=' ', ' ') +
IIF((pos('GMT', GMTFormat)>0) and (h=0), 'GMT',
IIF(h<0,'+','-') + Format('%.2d', [Abs(h)]) +
IIF(pos(':', GMTFormat)>0, ':') +
IIF((pos('0000',GMTFormat)>0) or (pos('00:00',GMTFormat)>0), '00'));
end;
function FileTimeToDateTime(ft: FILETIME) : TDateTime;
var
st : SYSTEMTIME;
lt : FILETIME;
begin
FillChar(st, SizeOf(st), 0);
FillChar(lt, SizeOf(lt), 0);
FileTimeToLocalFileTime(ft, lt);
FileTimeToSystemTime(lt, st);
result := SystemTimeToDateTime(st);
end;
function FileTimeToGMTDateTime(Filename: string; const DTFormat: string = 'ddd, dd mmm yyyy hh:nn:ss "GMT"'): string;
var
fh : THandle;
fLastWriteTime : TFileTime;
dt: TDateTime;
begin
result := '';
if FileExists(Filename) then
begin
fh := FileOpen(Filename, fmOpenRead or fmShareDenyNone);
try
if fh >0 then // <> INVALID_HANDLE_VALUE then
if GetFileTime(fh, nil, nil, @fLastWriteTime) then
begin
dt := FileTimeToDateTime(fLastWriteTime);
result := FormatGMTDateTime(DTFormat, dt);
end;
finally
FileClose(fh);
end;
end;
end;