function GetTime:TDateTime;
var
XmlHttp: Variant;
datetxt : String;
DateLst : TStringList;
mon: String;
timeGMT,GetNetTime:TDateTime;
begin
result := 0;
try
XmlHttp := createoleobject(‘Microsoft.XMLHTTP‘);
try
XmlHttp.Open( ‘Get‘, ‘http://time.tianqi.com/‘, False);
XmlHttp.send;
datetxt :=XmlHttp.getResponseHeader(‘Date‘);
except
Exit;
end;
// Mon, 12 Apr 2021 01:24:46 GMT
datetxt := Copy(datetxt,Pos(‘,‘,datetxt)+1,100);
datetxt := StringReplace(datetxt,‘GMT‘,‘‘,[]);
datetxt := Trim(datetxt);
datetxt := StringReplace(datetxt,‘ ‘,‘=‘,[]);
DateLst := TStringList.Create;
DateLst.Delimiter := ‘=‘;
DateLst.DelimitedText := datetxt;
if DateLst[1] = ‘Jan‘ then
mon := ‘01‘
else if DateLst[1] = ‘Feb‘ then
mon := ‘02‘
else if DateLst[1] = ‘Mar‘ then
mon := ‘03‘
else if DateLst[1] = ‘Apr‘ then
mon := ‘04‘
else if DateLst[1] = ‘Mar‘ then
mon := ‘05‘
else if DateLst[1] = ‘Jun‘ then
mon := ‘06‘
else if DateLst[1] = ‘Jul‘ then
mon := ‘07‘
else if DateLst[1] = ‘Aug‘ then
mon := ‘08‘
else if DateLst[1] = ‘Sep‘ then
mon := ‘09‘
else if DateLst[1] = ‘Oct‘ then
mon := ‘10‘
else if DateLst[1] = ‘Nov‘ then
mon := ‘11‘
else if DateLst[1] = ‘Dec‘ then
mon := ‘12‘ ;
timeGMT := StrToDateTime(DateLst[2]+‘-‘+mon+‘-‘+DateLst[0]+‘ ‘+ DateLst[3]);
GetNetTime := IncHour(TimeGMT,8);
finally
FreeAndNil(DateLst);
XmlHttp := unassigned;
end;
Result := GetNetTime ;
end;