Entwickler-Ecke

Delphi Language (Object-Pascal) / CLX - Zeitumstellung in Delphi


phoque - Mo 14.11.05 14:08
Titel: Zeitumstellung in Delphi
Hallo,

ich habe zwar schon gesucht aber nichts gefunden.
Gibt es irgendwie eine Funktion die mir eine Zeit mit Datum (MEZ) in GMT umrechnet?
Ich habe zwar wohl schon was gefunden, aber dabei wird dann die Zeitumstellung nicht beruecksichtigt.

gruss

phoque


Moderiert von user profile iconraziel: Topic aus VisualCLX (Component Library for Cross Platform) verschoben am Mo 14.11.2005 um 13:16


chrisw - Mo 14.11.05 14:48

Das geht wie folgt :


Delphi-Quelltext
1:
2:
3:
4:
var TZ : Time_Zone_Information;

GetTimeZoneInformation(TZ);
Stunden der aktuellen Rechnerzeit - TZ.Bias div 60// = GMT


Moderiert von user profile iconAXMD: Delphi-Tags hinzugefügt.


phoque - Di 15.11.05 13:03

bei mir rechnet er da irgendwie immer nur nen Tag drauf, egal ob winter oder sommerzeit??


Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
var
 lDateConverter: TXsCustomDateTime;
 aValue: TDateTime;
 var TZ : Time_Zone_Information;
 ...
begin
 showmessage(Datum);           //2003-03-04 16:35
 GetTimeZoneInformation(TZ);
 aValue := strtodatetime(Datum) - TZ.Bias div 60// = GMT
 showmessage(dateTimetostr(aValue));        //2003-03-05 16:35
 ...
end;


phoque


Delete - Di 15.11.05 13:18

Nimm mal TZ.DaylightBias

Zitat:

DaylightBias
Bias value to be used during local time translations that occur during daylight saving time. This member is ignored if a value for the DaylightDate member is not supplied.
This value is added to the value of the Bias member to form the bias used during daylight saving time. In most time zones, the value of this member is –60.


chrisw - Di 15.11.05 13:31

Vielleicht hilft Dir das ?


Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
procedure TForm1.Button1Click(Sender: TObject);
var tt : TDateTime;
    ST : _SystemTime;
    TZ : Time_Zone_Information;
begin
    tt := now;
    DecodeTime(tt,ST.wHour,ST.wMinute,ST.wSecond,ST.wMilliSeconds);
    GetTimeZoneInformation(TZ);
    ST.wHour := ST.wHour + TZ.Bias div 60 + TZ.DaylightBias div 60
//Bias ist der Zeitabstand bis zu GMT in Minuten //hier -60 Minuten
//DayLightBias ist der Zeitabstand von Sommerzeit zur Winterzeit in Minuten (Wobei Winterzeit 0 und Sommerzeit -60 ist)
    Showmessage(TimeToStr(EncodeTime(ST.wHour,ST.wMinute,ST.wSecond,ST.wMilliSeconds)));
 end;



EDIT: Hier muss natürlich noch der Fehler abgefandegn werden, wenn ST.wHour nach der Manipulation < 0 ist. (also z,Bsp bei Sommerzeit um 0100 Uhr Nacht wäre St.wHour ja -1)