1st post
Delphi
code posted
by
artem.larin
created at 22 May 18:52
Edit
|
Back
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
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; |
1.36 KB in 3 ms with coderay