没有数据库的前提下,如何获得服务器的时间?局域网 如题在先等待 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 取远程机器日期时间unit Unit3;interfaceuses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls;type TTODInfo = record ElapsedTime: Integer; {number of seconds since 00:00:00 January 1, 1970} Milliseconds: Integer; {number of milliseconds since last system reset} Hours: Integer; {current hour (0-23)} Minutes: Integer; {current minute (0-59)} Seconds: Integer; {current second (0-59)} Hunds: Integer; {current hundredth of a second (0-99)} TimeZone: Integer; {time against GMT in minutes} {west of Greenwich gives positive, east negative values} {value of -1 means undefined time zone} Interval: Integer; {clock tick interval in ten-thousandth of a second (0.0001 s)} Day: Integer; {day of the month (1-31)} Month: Integer; {month of the year (1-12)} Year: Integer; {year} Weekday: Integer; {day of the week (0-6) 0 = Sunday, 1 = Monday etc.} end; PTODInfo = ^TTODInfo;type TForm1 = class(TForm) Button1: TButton; Label1: TLabel; procedure Button1Click(Sender: TObject); private { Private declarations } public { Public declarations } end;var Form1: TForm1;const netapi32 = 'netapi32.dll';function NetApiBufferFree(Buffer: Pointer): Integer; stdcall;function NetRemoteTOD(UNCServerName: PWideChar; Info: Pointer): Integer; stdcall;function ServerTime(const UNCServer: string; var Stamp: TDateTime): Integer;implementation{$R *.dfm}function NetApiBufferFree; external netapi32 name 'NetApiBufferFree';function NetRemoteTOD; external netapi32 name 'NetRemoteTOD';function ServerTime(const UNCServer: string; var Stamp: TDateTime): Integer;var ServerName: PWideChar; tod: PTODInfo; Year, Month, Day, Hour, Min, Sec, MSec: Word;begin GetMem(ServerName, (Length(UNCServer) + 1) * SizeOf(WideChar)); try ServerName := StringToWideChar(UNCServer, ServerName, Length(UNCServer) + 1); Result := NetRemoteTOD(ServerName, @tod); if Result = 0 then begin try Year := tod^.Year; Month := tod^.Month; Day := tod^.Day; Hour := tod^.Hours; Min := tod^.Minutes; Sec := tod^.Seconds; MSec := tod^.Hunds * 10; if tod^.TimeZone = -1 then {undefined timezone} Stamp := EncodeDate(Year, Month, Day) + EncodeTime(Hour, Min, Sec, MSec) else Stamp := EncodeDate(Year, Month, Day) + EncodeTime(Hour, Min, Sec, MSec) - (tod^.TimeZone / 1440); finally NetApiBufferFree(tod); end; end; finally FreeMem(ServerName); end;end;procedure TForm1.Button1Click(Sender: TObject);var t: TDateTime;begin ServerTime('server', t); label1.Caption := DateTimeToStr(t);end;end. t:=GetRemoteDateTime('\\192.168.1.1'); // 主機前要加 \\, 而且要先 trust 過 showmessage(formatdatetime('yyyy/mm/dd hh:nn:ss',t)); 为什么一点按钮是1899年的时间呢?t:=GetRemoteDateTime('\\192.168.1.1'); 这个放在哪里? 输入自己机器的ip就是正确的时间,输入局域网其他机器的时间就是1899年?而且要先 trust 過是什么意思? 用这个 ServerTime('server', t); label1.Caption := DateTimeToStr(t);你可先在dos下c:\>net time //192.168.1.1看看 你可先在dos下c:\>net time //192.168.1.1在dos下运行这个命令,提示192.168.1.1未知但是192.168.1.1这个网址可以ping通 c:\>net time //192.168.1.1这个"//"错了,应该是"\\" delphi Timage控件画虚框的问题 如何左右调换字符串 敢问大家找工作的时候都通过什么途径啊?会去招聘会逛吗?(散散分先) 神经Borland公司!!! 如何用TABLE去取SEQUENCE里面的数据, TreeView的使用!在线等! 555为什么要删除我的贴子啊?不要啊...... 如何将多个图片压缩成为mepg格式的影像文件?1000分!一定给! TDBLookupCombox怎么设置默认值? 项目合作,软件源代码 删除相关数据记录? 安装Dephi6时出现"Internet Error 2349"错误???
unit Unit3;interfaceuses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;type
TTODInfo = record
ElapsedTime: Integer; {number of seconds since 00:00:00 January 1, 1970}
Milliseconds: Integer; {number of milliseconds since last system reset}
Hours: Integer; {current hour (0-23)}
Minutes: Integer; {current minute (0-59)}
Seconds: Integer; {current second (0-59)}
Hunds: Integer; {current hundredth of a second (0-99)}
TimeZone: Integer; {time against GMT in minutes}
{west of Greenwich gives positive, east negative values}
{value of -1 means undefined time zone}
Interval: Integer; {clock tick interval in ten-thousandth of a second (0.0001 s)}
Day: Integer; {day of the month (1-31)}
Month: Integer; {month of the year (1-12)}
Year: Integer; {year}
Weekday: Integer; {day of the week (0-6) 0 = Sunday, 1 = Monday etc.}
end;
PTODInfo = ^TTODInfo;type
TForm1 = class(TForm)
Button1: TButton;
Label1: TLabel;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;var
Form1: TForm1;
const
netapi32 = 'netapi32.dll';function NetApiBufferFree(Buffer: Pointer): Integer; stdcall;
function NetRemoteTOD(UNCServerName: PWideChar; Info: Pointer): Integer; stdcall;function ServerTime(const UNCServer: string; var Stamp: TDateTime): Integer;implementation{$R *.dfm}function NetApiBufferFree; external netapi32 name 'NetApiBufferFree';
function NetRemoteTOD; external netapi32 name 'NetRemoteTOD';function ServerTime(const UNCServer: string; var Stamp: TDateTime): Integer;
var
ServerName: PWideChar;
tod: PTODInfo;
Year, Month, Day, Hour, Min, Sec, MSec: Word;
begin
GetMem(ServerName, (Length(UNCServer) + 1) * SizeOf(WideChar));
try
ServerName := StringToWideChar(UNCServer, ServerName, Length(UNCServer) + 1);
Result := NetRemoteTOD(ServerName, @tod);
if Result = 0 then
begin
try
Year := tod^.Year;
Month := tod^.Month;
Day := tod^.Day;
Hour := tod^.Hours;
Min := tod^.Minutes;
Sec := tod^.Seconds;
MSec := tod^.Hunds * 10;
if tod^.TimeZone = -1 then {undefined timezone}
Stamp := EncodeDate(Year, Month, Day) +
EncodeTime(Hour, Min, Sec, MSec)
else
Stamp := EncodeDate(Year, Month, Day) +
EncodeTime(Hour, Min, Sec, MSec) - (tod^.TimeZone / 1440);
finally
NetApiBufferFree(tod);
end;
end;
finally
FreeMem(ServerName);
end;
end;procedure TForm1.Button1Click(Sender: TObject);
var
t: TDateTime;
begin
ServerTime('server', t);
label1.Caption := DateTimeToStr(t);
end;end. t:=GetRemoteDateTime('\\192.168.1.1'); // 主機前要加 \\, 而且要先 trust 過
showmessage(formatdatetime('yyyy/mm/dd hh:nn:ss',t));
t:=GetRemoteDateTime('\\192.168.1.1'); 这个放在哪里?
而且要先 trust 過是什么意思?
ServerTime('server', t);
label1.Caption := DateTimeToStr(t);你可先在dos下c:\>net time //192.168.1.1看看
c:\>net time //192.168.1.1
在dos下运行这个命令,提示192.168.1.1未知
但是192.168.1.1这个网址可以ping通
这个"//"错了,应该是"\\"