获得internet时间的问题?

在网上下载的源码都提示找不到控件.  

   

  能给个最简单的吗?  

  还有说明一下控件在要哪儿添加.和使用方法.

给分自己行吗???  
  结帖了。

给分自己行吗???  
  ————  
  不可以  
  JF

//直接使用   TClientSocket  
  unit   TimeDllU;  
   
  interface  
   
  uses  
      Windows,   Messages,   SysUtils,   Classes,   Graphics,   Controls,   Forms,   Dialogs,  
      ScktComp;  
   
  type  
      TDTForm   =   class(TForm)  
          DTSock:   TClientSocket;  
          procedure   DTSockRead(Sender:   TObject;   Socket:   TCustomWinSocket);  
      private  
          {   Private   declarations   }  
      public  
          {   Public   declarations   }  
      end;  
   
  const  
      TimerServer:   string=’203.129.68.14′;//香港时间服务器  
   
  var  
      DTForm:   TDTForm=nil;  
      DT:   TDateTime=-1;  
      DTReady:   Boolean=False;  
   
      procedure   TimeDllInit();   stdcall  
      function   TimeDllGetTime(doadj:   Boolean):   TDateTime;   stdcall  
      procedure   TimeDllFinish();   stdcall  
   
  implementation  
   
  {$R   *.DFM}  
   
  procedure   TimeDllInit();  
  begin  
      DTForm   :=   TDTForm.Create(Application);  
  end;  
   
  procedure   TimeDllFinish();  
  begin  
      DTForm.Free();  
  end;  
   
  var  
      pTimeZoneInformation:   TTimeZoneInformation;  
  function   TimeDllGetTime(doadj:   Boolean):   TDateTime;  
  var  
      systim:   SYSTEMTIME;  
      hToken:   THANDLE;  
      tkp:   TOKEN_PRIVILEGES;  
      tmp:   DWORD;  
      preTick:   DWORD;  
  begin  
      DT   :=   -1;  
      DTReady   :=   False;  
      try  
          DTForm.DTSock.Host   :=   TimerServer;  
          DTForm.DTSock.Open();  
          preTick   :=   GetTickCount();  
          While   GetTickCount()   –   preTick   <   5000   do  
          begin  
              Sleep(10);  
              Application.ProcessMessages();  
              if   DTReady   then  
                  Break;  
          end;  
      except  
      else  
          ;  
      end;  
      if   DTReady   then  
      begin  
          GetTimeZoneInformation(pTimeZoneInformation);  
          DT   :=   DT   –   pTimeZoneInformation.Bias/(24*60);   //(国际标准时间转换到本地时间)  
          if   doadj   then  
              if   DT   >   38880   then  
              begin  
                  DecodeDate(DT,   systim.wYear,   systim.wMonth,   systim.wDay);  
                  DecodeTime(DT,   systim.wHour,   systim.wMinute,   systim.wSecond,   systim.wMilliSeconds);  
                  if   OpenProcessToken(GetCurrentProcess(),   TOKEN_ADJUST_PRIVILEGES   or   TOKEN_QUERY,   hToken)   then  
                  begin  
                      LookupPrivilegeValue(nil,   ‘SeSystemTimePrivilege’,   tkp.Privileges[0].Luid);  
                      tkp.PrivilegeCount   :=   1;   //   one   privilege   to   set  
                      tkp.Privileges[0].Attributes   :=   SE_PRIVILEGE_ENABLED;  
                      tmp   :=   0;  
                      AdjustTokenPrivileges(hToken,   FALSE,   tkp,   0,   nil,   tmp);  
                  end;  
                  SetLocalTime(systim);  
              end;  
      end;  
      Result   :=   DT;  
  end;  
   
  function   MouthStr2Int(ms:   string):   Word;  
  const  
      MouthStrs:   array   [1..12]   of   string   =  
      (  
          ‘JAN’,  
          ‘FEB’,  
          ‘MAR’,  
          ‘APR’,  
          ‘MAY’,  
          ‘JUN’,  
          ‘JUL’,  
          ‘AUG’,  
          ‘SEP’,  
          ‘OCT’,  
          ‘NOV’,  
          ‘DEC’  
      );  
  var  
      i:   integer;  
  begin  
      ms   :=   UpperCase(ms);  
      for   i   :=   1   to   12   do  
      begin  
          if   ms   =   MouthStrs[i]   then  
          begin  
              Result   :=   i;  
              Exit;  
          end;  
      end;  
      Result   :=   0;  
  end;  
   
  procedure   TDTForm.DTSockRead(Sender:   TObject;   Socket:   TCustomWinSocket);  
  var  
      sTime   :   string;  
      systim:   SYSTEMTIME;  
      i:   integer;  
      ti:   TDateTime;  
  begin  
      sTime   :=   Socket.ReceiveText;  
      if   Length(sTime)   <   32   then  
      begin  
          i   :=   Pos(‘   ‘,   sTime);  
          if   i   =   0   then  
              Exit;  
          systim.wDay   :=   StrToInt(Copy(sTime,   1,   i-1));  
          Delete(sTime,   1,   i);  
          i   :=   Pos(‘   ‘,   sTime);  
          if   i   =   0   then  
              Exit;  
          systim.wMonth   :=   MouthStr2Int(Copy(sTime,   1,   i-1));  
          Delete(sTime,   1,   i);  
          i   :=   Pos(‘   ‘,   sTime);  
          if   i   =   0   then  
              Exit;  
          systim.wYear   :=   StrToInt(Copy(sTime,   1,   i-1));  
          Delete(sTime,   1,   i);  
   
          i   :=   Pos(‘   ‘,   sTime);  
          if   i   =   0   then  
              Exit;  
          ti   :=   StrToTime(Copy(sTime,   1,   i-1));  
          Delete(sTime,   1,   i);  
   
          if   UpperCase(Copy(sTime,   1,   3))   =   ‘HKT’   then  
          begin  
              DT   :=   EncodeDate(systim.wYear,   systim.wMonth,   systim.wDay);  
              DT   :=   DT   +   ti;  
              DT   :=   DT   –   (8/24);   //   HK   Time   to   UTC   (香港时间转换到国际标准时间)  
              DTReady   :=   True;  
          end;  
      end;  
  end;  
   
  end.  
 

//   改了下,用全角空格对齐  
  unit   TimeDllU;  
   
  interface  
   
  uses  
  Windows,   Messages,   SysUtils,   Classes,   Graphics,   Controls,   Forms,   Dialogs,  
  ScktComp;  
   
  type  
  TDTForm   =   class(TForm)  
  DTSock:   TClientSocket;  
  procedure   DTSockRead(Sender:   TObject;   Socket:   TCustomWinSocket);  
  private  
  {   Private   declarations   }  
  public  
  {   Public   declarations   }  
  end;  
   
  const  
  TimerServer:   string=’203.129.68.14′;//香港时间服务器  
   
  var  
  DTForm:   TDTForm=nil;  
  DT:   TDateTime=-1;  
  DTReady:   Boolean=False;  
   
  procedure   TimeDllInit();   stdcall  
  function   TimeDllGetTime(doadj:   Boolean):   TDateTime;   stdcall  
  procedure   TimeDllFinish();   stdcall  
   
  implementation  
   
  {$R   *.DFM}  
   
  procedure   TimeDllInit();  
  begin  
  DTForm   :=   TDTForm.Create(Application);  
  end;  
   
  procedure   TimeDllFinish();  
  begin  
  DTForm.Free();  
  end;  
   
  var  
  pTimeZoneInformation:   TTimeZoneInformation;  
  function   TimeDllGetTime(doadj:   Boolean):   TDateTime;  
  var  
  systim:   SYSTEMTIME;  
  hToken:   THANDLE;  
  tkp:   TOKEN_PRIVILEGES;  
  tmp:   DWORD;  
  preTick:   DWORD;  
  begin  
  DT   :=   -1;  
  DTReady   :=   False;  
  try  
  DTForm.DTSock.Host   :=   TimerServer;  
  DTForm.DTSock.Open();  
  preTick   :=   GetTickCount();  
  While   GetTickCount()   –   preTick   <   5000   do  
  begin  
  Sleep(10);  
  Application.ProcessMessages();  
  if   DTReady   then  
  Break;  
  end;  
  except  
  else  
  ;  
  end;  
  if   DTReady   then  
  begin  
  GetTimeZoneInformation(pTimeZoneInformation);  
  DT   :=   DT   –   pTimeZoneInformation.Bias/(24*60);   //(国际标准时间转换到本地时间)  
  if   doadj   then  
  if   DT   >   38880   then  
  begin  
  DecodeDate(DT,   systim.wYear,   systim.wMonth,   systim.wDay);  
  DecodeTime(DT,   systim.wHour,   systim.wMinute,   systim.wSecond,   systim.wMilliSeconds);  
  if   OpenProcessToken(GetCurrentProcess(),   TOKEN_ADJUST_PRIVILEGES   or   TOKEN_QUERY,   hToken)   then  
  begin  
  LookupPrivilegeValue(nil,   ‘SeSystemTimePrivilege’,   tkp.Privileges[0].Luid);  
  tkp.PrivilegeCount   :=   1;   //   one   privilege   to   set  
  tkp.Privileges[0].Attributes   :=   SE_PRIVILEGE_ENABLED;  
  tmp   :=   0;  
  AdjustTokenPrivileges(hToken,   FALSE,   tkp,   0,   nil,   tmp);  
  end;  
  SetLocalTime(systim);  
  end;  
  end;  
  Result   :=   DT;  
  end;  
   
  function   MouthStr2Int(ms:   string):   Word;  
  const  
  MouthStrs:   array   [1..12]   of   string   =  
  (  
  ‘JAN’,  
  ‘FEB’,  
  ‘MAR’,  
  ‘APR’,  
  ‘MAY’,  
  ‘JUN’,  
  ‘JUL’,  
  ‘AUG’,  
  ‘SEP’,  
  ‘OCT’,  
  ‘NOV’,  
  ‘DEC’  
  );  
  var  
  i:   integer;  
  begin  
  ms   :=   UpperCase(ms);  
  for   i   :=   1   to   12   do  
  begin  
  if   ms   =   MouthStrs[i]   then  
  begin  
  Result   :=   i;  
  Exit;  
  end;  
  end;  
  Result   :=   0;  
  end;  
   
  procedure   TDTForm.DTSockRead(Sender:   TObject;   Socket:   TCustomWinSocket);  
  var  
  sTime   :   string;  
  systim:   SYSTEMTIME;  
  i:   integer;  
  ti:   TDateTime;  
  begin  
  sTime   :=   Socket.ReceiveText;  
  if   Length(sTime)   <   32   then  
  begin  
  i   :=   Pos(‘   ‘,   sTime);  
  if   i   =   0   then  
  Exit;  
  systim.wDay   :=   StrToInt(Copy(sTime,   1,   i-1));  
  Delete(sTime,   1,   i);  
  i   :=   Pos(‘   ‘,   sTime);  
  if   i   =   0   then  
  Exit;  
  systim.wMonth   :=   MouthStr2Int(Copy(sTime,   1,   i-1));  
  Delete(sTime,   1,   i);  
  i   :=   Pos(‘   ‘,   sTime);  
  if   i   =   0   then  
  Exit;  
  systim.wYear   :=   StrToInt(Copy(sTime,   1,   i-1));  
  Delete(sTime,   1,   i);  
   
  i   :=   Pos(‘   ‘,   sTime);  
  if   i   =   0   then  
  Exit;  
  ti   :=   StrToTime(Copy(sTime,   1,   i-1));  
  Delete(sTime,   1,   i);  
   
  if   UpperCase(Copy(sTime,   1,   3))   =   ‘HKT’   then  
  begin  
  DT   :=   EncodeDate(systim.wYear,   systim.wMonth,   systim.wDay);  
  DT   :=   DT   +   ti;  
  DT   :=   DT   –   (8/24);   //   HK   Time   to   UTC   (香港时间转换到国际标准时间)  
  DTReady   :=   True;  
  end;  
  end;  
  end;  
   
  end.  
 

Unit  
  NMTime  
   
  Description  
  The   TNMTime   component   is   used   for   getting   the   time   from   Internet   time   servers,   as   described   in   RFC   868.

分给我.

原文链接:https://www.cnblogs.com/delphi2007/archive/2008/09/23/1296503.html

原创文章,作者:优速盾-小U,如若转载,请注明出处:https://www.cdnb.net/bbs/archives/33813

(0)
优速盾-小U的头像优速盾-小U
上一篇 2025年8月23日 03:33
下一篇 2025年8月23日 16:45

相关推荐

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注

优速盾注册领取大礼包www.cdnb.net
/sitemap.xml