获得internet 时间的问题? 在网上下载的源码都提示找不到控件.能给个最简单的吗?还有说明一下控件在要哪儿添加.和使用方法. 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 //直接使用 TClientSocketunit TimeDllU;interfaceuses 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(); stdcallimplementation{$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;interfaceuses 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(); stdcallimplementation{$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. UnitNMTimeDescriptionThe TNMTime component is used for getting the time from Internet time servers, as described in RFC 868. 初学dephi三层结构,请大家多多指教 声道转换的问题 各位前辈,excel的操作代码我看不懂,能否我解释下,谢谢! :::::菜题::如何查询快(视图,存储过程,执行SQL语句)::::: 为何字段中无内容还有提示出现? 用query更新数据库 创智怎样? ADO的发布问题,请帮忙 我是WANG0110,请看我发的“题目以定”热血程序员参与进来吧!!! 如何打印memo字段的内容呢? 动态数组不能与字符串相互赋值 delphi怎样让窗口在屏幕上居中
unit TimeDllU;interfaceuses
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(); stdcallimplementation{$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;interfaceuses
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(); stdcallimplementation{$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.
NMTimeDescription
The TNMTime component is used for getting the time from Internet time servers, as described in RFC 868.