Delphi-PRAXiS
Seite 1 von 3  1 23      

Delphi-PRAXiS (https://www.delphipraxis.net/forum.php)
-   Object-Pascal / Delphi-Language (https://www.delphipraxis.net/32-object-pascal-delphi-language/)
-   -   Delphi Abweichung von UTC bekommen (https://www.delphipraxis.net/92681-abweichung-von-utc-bekommen.html)

Andreas L. 24. Mai 2007 09:54


Abweichung von UTC bekommen
 
Hi,
ich muss ein Datum + Uhrzeit in folgenden Format darstellen:

Zitat:

Format: 2005-01-08T17:10:47-05:00
-05:00 ist die Abweichung von UTC. Doch wie bekommen ich diese Abweichung?

Bisher habe ich nur folgendes:

Delphi-Quellcode:
 
var
 bla: String;
begin
 bla:= FormatDateTime('yyyy-mm-ddhh:nn:ss', Now);
 Insert('T', bla, 9);
Gibt es eine Funktion die mir diese Abweichung übergibt?

chaosben 24. Mai 2007 10:17

Re: Abweichung von UTC bekommen
 
Zitat:

Zitat von Das Microsoft Platform SDK
GetTimeZoneInformation

The GetTimeZoneInformation function retrieves the current time-zone parameters. These parameters control the translations between Coordinated Universal Time (UTC) and local time.

:)

Andreas L. 24. Mai 2007 10:21

Re: Abweichung von UTC bekommen
 
Ich habe mir das im PSDK mal angeschaut. Aber wie verwende ich das?

Zitat:

DWORD GetTimeZoneInformation(
LPTIME_ZONE_INFORMATION lpTimeZoneInformation
);


chaosben 24. Mai 2007 10:42

Re: Abweichung von UTC bekommen
 
Z.B. so:
Delphi-Quellcode:
var
  tzi : TTimeZoneInformation;
begin
  GetTimeZoneInformation(tzi);
  MessageDlg(intToStr(tzi.Bias), mtWarning, [mbOK], 0);
end;

Andreas L. 24. Mai 2007 10:47

Re: Abweichung von UTC bekommen
 
Hmm... das gibt mir jetzt -60 zurück. Also -1 Stunde. Haben wir hier in Deutschland nicht +1 Stunde?

Luckie 24. Mai 2007 10:53

Re: Abweichung von UTC bekommen
 
Sommer- und Winterzeit berücksichtigt?

Andreas L. 24. Mai 2007 10:56

Re: Abweichung von UTC bekommen
 
Zitat:

Zitat von Luckie
Sommer- und Winterzeit berücksichtigt?

Ähm... Nö, hab nru den Code von chaosben kopiert. Wie berücksichtige ich denn die Sommer- und Winterzeit?

Luckie 24. Mai 2007 10:59

Re: Abweichung von UTC bekommen
 
In dem du sie entsprechend dazu addierst oder abziehst oder wie auch immer. Und bevor du fragst: MSDN-Library durchsuchenGetTimeZoneInformation!

Andreas L. 24. Mai 2007 11:06

Re: Abweichung von UTC bekommen
 
Auf den von dir verlinkten Artikel war ich ja schon. Aber dort steht nirgendwo was wie man herausbekommt ob gerade Sommer- oder Winterzeit ist. Wie lautet denn die benötigte Funktion?

shmia 24. Mai 2007 11:07

Re: Abweichung von UTC bekommen
 
Delphi-Quellcode:
// liefert den Abstand der lokalen Zeit zu UTC
// UTC = lokaleZeit + GetTimeZoneBias
function GetTimeZoneBias:TDateTime;
const
   MINUTES_PER_DAY = 24.0 * 60.0;
var
  tzi : TTimeZoneInformation;
begin
   case GetTimeZoneInformation(tzi) of
      TIME_ZONE_ID_STANDARD:
         result := (tzi.Bias) / MINUTES_PER_DAY;

      TIME_ZONE_ID_DAYLIGHT: // Sommerzeit
         Result := (tzi.Bias+tzi.DaylightBias) / MINUTES_PER_DAY;
   else
      Result := 0.0;
   end;
end;


Alle Zeitangaben in WEZ +1. Es ist jetzt 12:24 Uhr.
Seite 1 von 3  1 23      

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024 by Thomas Breitkreuz