小弟问个菜鸟问题:Delphi中取当天日期可以调Date()或Now(),要获取服务器的时间应该如何处理呢,请高手指导
解决方案 »
- 如何修改网络连接中VPN属性里的IP地址??
- delphi7中,我想将数据库中ACCESS表的符合条件的某几个字段的值导出到Excel表中,Excel表的格式已预先设定。请各位帮帮忙,谢谢~
- 求助一个关于动态创建菜单项的事件响应问题?
- 关于屏蔽系统功能键的问题。
- 在delphi 当中如何控制excel 当中图片的大小!!最后十分都给您了,这可是卖血利来的钱啊。
- 请问怎么将Excel文件转换为dbase3格式!!急!!
- 我的程序中有四個主菜單,人事,考勤,工資,系統管理,我希望
- 如何使用radiogroup?请教
- Delphi操作word的 RPC不能使用错问题!
- richedit的文本替换?
- 如何在自己自定义的类里封装TADOQuery等类
- 请帮忙解决WinXP与Win98双系统的启动难题?(在线等待)
不然的话,你要用Socket控件返回了。
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));