本地电脑的时区,如何获得呢?

解决方案 »

  1.   

    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;
    得出中国标准时间
      

  2.   

    这个估计更切合实际
    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;
      

  3.   

    楼主参考一下GetTimeZoneInformation的MSDN,这个是获取本地时间区域信息的。
      

  4.   

    可以通过转换为本地时间然后计算时差
    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;
      

  5.   

    GetTimeZoneInformation函数没有那个时区参数,就是控制面板里面的那个参数,比如现在电脑上设置的是北京+0800,应该有个函数得到这个0800,如果在控制面板里面设置为曼谷+0700,那么这个函数应该返回0700。
      

  6.   

    谢谢大家,unsigned大侠完全实现了,lovelymelon基本实现了,看来确实是相当复杂:)