var tm:_TIME_ZONE_INFORMATION; s,s1:WideString; i:Integer; begin GetTimeZoneInformation(tm); for i:=0 to 31 do s:=s+tm.StandardName[i]; end; 得出中国标准时间
这个估计更切合实际 procedure TForm1.Button16Click(Sender: TObject); var m_timezone:TIME_ZONE_INFORMATION; szTimeZone:array[0..1] of string; i:integer; dTimezone:double; iTimezone:integer; dZone:double; begin GetTimeZoneInformation(m_timezone); szTimeZone[0]:=m_timezone.StandardName; i:=m_timezone.Bias; dTimezone:=-1*(i / 60); // dTimeZone:=dTimeZone mod 1; iTimezone:=Trunc(dTimezone); dZone:=dTimezone-iTimezone; dZone:=abs(dZone*60); if dZone=0 then begin if dTimezone>0 then showmessage('(GMT+'+inttostr(iTimezone)+':00) '+szTimeZone[0]) else showmessage('(GMT'+inttostr(iTimezone)+':00) '+szTimeZone[0]); end else begin if dTimezone>0 then showmessage('(GMT+'+inttostr(iTimezone)+':'+floattostr(dZone)+') '+szTimeZone[0]) else showmessage('(GMT'+inttostr(iTimezone)+':'+floattostr(dZone)+') '+szTimeZone[0]); end; end;
楼主参考一下GetTimeZoneInformation的MSDN,这个是获取本地时间区域信息的。
可以通过转换为本地时间然后计算时差 var CurrentTime,adjzoneTime: TDateTime; file_CurrentTime, file_adjzoneTime: FILETIME; tmp_SysTime: SYSTEMTIME; begin CurrentTime := Now; DateTimeToSystemTime(CurrentTime, tmp_SysTime); SystemTimeToFileTime(tmp_SysTime, file_CurrentTime); FileTimeToLocalFileTime(file_CurrentTime, file_adjzoneTime); FileTimeToSystemTime(file_adjzoneTime, tmp_SysTime); adjzoneTime := SystemTimeToDateTime(tmp_SysTime); if adjzoneTime > CurrentTime then ShowMessage(FormatDateTime('+hhnn', adjzoneTime - CurrentTime)) else ShowMessage(FormatDateTime('-hhnn', adjzoneTime - CurrentTime)); end;
tm:_TIME_ZONE_INFORMATION;
s,s1:WideString;
i:Integer;
begin
GetTimeZoneInformation(tm);
for i:=0 to 31 do
s:=s+tm.StandardName[i];
end;
得出中国标准时间
procedure TForm1.Button16Click(Sender: TObject);
var
m_timezone:TIME_ZONE_INFORMATION;
szTimeZone:array[0..1] of string;
i:integer;
dTimezone:double;
iTimezone:integer;
dZone:double;
begin
GetTimeZoneInformation(m_timezone);
szTimeZone[0]:=m_timezone.StandardName;
i:=m_timezone.Bias;
dTimezone:=-1*(i / 60);
// dTimeZone:=dTimeZone mod 1;
iTimezone:=Trunc(dTimezone);
dZone:=dTimezone-iTimezone;
dZone:=abs(dZone*60);
if dZone=0 then begin
if dTimezone>0 then
showmessage('(GMT+'+inttostr(iTimezone)+':00) '+szTimeZone[0])
else
showmessage('(GMT'+inttostr(iTimezone)+':00) '+szTimeZone[0]);
end else begin
if dTimezone>0 then
showmessage('(GMT+'+inttostr(iTimezone)+':'+floattostr(dZone)+') '+szTimeZone[0])
else
showmessage('(GMT'+inttostr(iTimezone)+':'+floattostr(dZone)+') '+szTimeZone[0]);
end;
end;
var
CurrentTime,adjzoneTime: TDateTime;
file_CurrentTime, file_adjzoneTime: FILETIME;
tmp_SysTime: SYSTEMTIME;
begin
CurrentTime := Now;
DateTimeToSystemTime(CurrentTime, tmp_SysTime);
SystemTimeToFileTime(tmp_SysTime, file_CurrentTime);
FileTimeToLocalFileTime(file_CurrentTime, file_adjzoneTime);
FileTimeToSystemTime(file_adjzoneTime, tmp_SysTime);
adjzoneTime := SystemTimeToDateTime(tmp_SysTime);
if adjzoneTime > CurrentTime then ShowMessage(FormatDateTime('+hhnn', adjzoneTime - CurrentTime))
else
ShowMessage(FormatDateTime('-hhnn', adjzoneTime - CurrentTime));
end;