Title / Description
Code var MainForm: TMainForm; implementation {$R *.dfm} function TzSpecificLocalTimeToSystemTime(lpTimeZoneInformation: PTimeZoneInformation; var lpLocalTime, lpUniversalTime: TSystemTime): BOOL; stdcall; external kernel32 name 'TzSpecificLocalTimeToSystemTime'; {$EXTERNALSYM TzSpecificLocalTimeToSystemTime} function SystemTimeToUTC(Sys : TDateTime):TDateTime; var TimeZoneInf : _TIME_ZONE_INFORMATION; SysTime,LocalTime: TSystemTime; begin if GetTimeZoneInformation(TimeZoneInf) < $FFFFFFFF then begin DatetimetoSystemTime(Sys, SysTime); if TzSpecificLocalTimeToSystemTime(@TimeZoneInf,SysTime,LocalTime) then result:=SystemTimeToDateTime(LocalTime) else result:=Sys; end else result:=Sys; end; // Example of usage UTC function ZeroNumber(Num: Integer): String; begin if Month < 10 then Result := '0' + IntToStr(Num) else Result := IntToStr(Num); end; procedure TMainForm.UTCTimerTimer(Sender: TObject); var Day, Month, Year: Word; Hour, Minute, Sec, Millisec: Word; UTC: TDateTime; begin UTC := SystemTimeToUTC(Now); DecodeDate(UTC, Year, Month, Day); DecodeTime(UTC, Hour, Minute, Sec, Millisec); CurrentUTCTimeLabel.Caption := ZeroNumber(Day) + '.' + ZeroNumber(Month) + '.' + IntToStr(Year) + ' ' + ZeroNumber(Hour) + ':' + ZeroNumber(Minute) + ':' + ZeroNumber(Sec); end;
Author
Highlight as C C++ CSS Clojure Delphi ERb Groovy (beta) HAML HTML JSON Java JavaScript PHP Plain text Python Ruby SQL XML YAML diff code