有关本地时间的问题 这恐怕谁都没有办法的就算你在程序中实现了他在CMOS改你也没有办法。 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 可以取服务器时间啊~~NTRemote DateTime:部分关键代码: PTime_Of_Day_Info = ^TTime_Of_Day_Info; TTime_Of_Day_Info = record tod_elapsedt :Integer; tod_msecs :Integer; tod_hours :Integer; tod_mins :Integer; tod_secs :Integer; tod_hunds :Integer; tod_timezone :LongInt; tod_tinterval :Integer; tod_day :Integer; tod_month :Integer; tod_year :Integer; tod_weekday :Integer; end;function NetRemoteTOD(ServerName :PWideChar; var buffer :pointer) :Integer; stdcall; external 'netapi32.dll';function NetApiBufferFree(buffer : Pointer) :Integer; stdcall; external 'netapi32.dll';function TNTRemoteDateTime.GetTOD(ServerName: WideString): Integer;var Buffer :pointer; Rek :PTime_Of_Day_Info; ADate :TDateTime; ATime :TDateTime; FinalTime :TDateTime; THours, TMins, TSecs, TMSecs :Word; TYear, TMonth, TDay :Word;begin result:=NetRemoteTOD(PWideChar(ServerName), Buffer); if result=0 then begin Rek:=PTime_Of_Day_Info(Buffer); FServerName :=ServerName; FElapseDt :=Rek.tod_elapsedt; FMSecs :=Rek.tod_msecs; FHours :=Rek.tod_hours; FMins :=Rek.tod_mins; FSecs :=Rek.tod_secs; FHunds :=Rek.tod_hunds; FTInterval :=Rek.tod_tinterval; If Rek.tod_timezone <> -1 then begin FTimeZone:=Rek.tod_timezone div 60; end else FTimeZone:=0; FDay :=Rek.tod_day; FMonth :=Rek.tod_month; FYear :=Rek.tod_year; FWeekDay :=Rek.tod_weekday; ADate:=EncodeDate(FYear, FMonth, FDay); ATime:=EnCodeTime(FHours, FMins, FSecs, FHunds); FinalTime:=StrToDateTime(DateTimeToStr(ADate) + ' ' + TimeToStr(ATime)); FinalTime:=FinalTime - (FTimeZone / 24); decodetime(FinalTime,THours, TMins,TSecs, TSecs); FHours:=Integer(THours); decodeDate(FinalTime,TYear, TMonth,TDay); FYear:=Integer(TYear); FMonth:=Integer(TMonth); FDay:=Integer(TDay); end; NetApiBufferFree(Buffer);end; 这个也是一种方案procedure AnsyTime(const DatabaseName:string);var td: _SYSTEMTIME; ft: FILETIME;begin{ DONE -oKingron -cOther : 同步服务器时间 } with TQuery.Create(Self) do try DatabaseName:=DatabaseName; SQL.Clear; SQL.Text := 'select td=getdate()'; Open; DateTimeToSystemTime(FieldByName('td').AsDateTime, td); SystemTimeToFileTime(td,ft); LocalFileTimeToFileTime(ft,ft); FileTimeToSystemTime(ft,td); SetSystemTime(td); finally Free; end;end; NetRemoteTOD:type TIME_OF_DAY_INFO=record tod_elapsedt:DWORD; tod_msecs:dword; tod_hours:dword; tod_mins:dword; tod_secs:dword; tod_hunds:dword; tod_timezone:longint; tod_tinterval:dword; tod_day:dword; tod_month:dword; tod_year:dword; tod_weekday:dword; end;procedure NetRemoteTOD(UncServerName:lptstr;var BufferPtr:TIME_OF_DAY_INFO);stdcall;external 'netapi.dll';如果第一个参数为Nil,则从本地机器取得时间。只能在NT上面使用! wylove(阿刚) 的方案也不错很容易实现不过似乎系统开销很大 开发连锁店软件一般会采用什么技术? 如何用case语句表达下列代码? ADOQuery1关于链接字符串的使用问题 DBGRID读取EXCEL 后刷新的问题,麻烦看看。。谢谢 以NoTifyIconData为例请教Delphi的api基础 支持三箭做斑竹! 在delphi中点样做多线程 如何打包Delphi程序 在线等待,谢谢!(关于combobox的简单问题) 关于DBgrid? 学习DELPHI好,还是学习C++ BUILDER好?为什么? 关于多线程的问题请教!
NTRemote DateTime:
部分关键代码:
PTime_Of_Day_Info = ^TTime_Of_Day_Info;
TTime_Of_Day_Info = record
tod_elapsedt :Integer;
tod_msecs :Integer;
tod_hours :Integer;
tod_mins :Integer;
tod_secs :Integer;
tod_hunds :Integer;
tod_timezone :LongInt;
tod_tinterval :Integer;
tod_day :Integer;
tod_month :Integer;
tod_year :Integer;
tod_weekday :Integer;
end;function NetRemoteTOD(ServerName :PWideChar;
var buffer :pointer) :Integer; stdcall; external 'netapi32.dll';function NetApiBufferFree(buffer : Pointer) :Integer; stdcall; external 'netapi32.dll';function TNTRemoteDateTime.GetTOD(ServerName: WideString): Integer;
var Buffer :pointer;
Rek :PTime_Of_Day_Info;
ADate :TDateTime;
ATime :TDateTime;
FinalTime :TDateTime;
THours,
TMins,
TSecs,
TMSecs :Word;
TYear,
TMonth,
TDay :Word;
begin result:=NetRemoteTOD(PWideChar(ServerName),
Buffer);
if result=0 then
begin
Rek:=PTime_Of_Day_Info(Buffer);
FServerName :=ServerName;
FElapseDt :=Rek.tod_elapsedt;
FMSecs :=Rek.tod_msecs;
FHours :=Rek.tod_hours;
FMins :=Rek.tod_mins;
FSecs :=Rek.tod_secs;
FHunds :=Rek.tod_hunds;
FTInterval :=Rek.tod_tinterval; If Rek.tod_timezone <> -1 then
begin
FTimeZone:=Rek.tod_timezone div 60;
end
else
FTimeZone:=0; FDay :=Rek.tod_day;
FMonth :=Rek.tod_month;
FYear :=Rek.tod_year;
FWeekDay :=Rek.tod_weekday; ADate:=EncodeDate(FYear, FMonth, FDay);
ATime:=EnCodeTime(FHours, FMins, FSecs, FHunds); FinalTime:=StrToDateTime(DateTimeToStr(ADate) + ' ' + TimeToStr(ATime));
FinalTime:=FinalTime - (FTimeZone / 24); decodetime(FinalTime,THours, TMins,TSecs, TSecs); FHours:=Integer(THours); decodeDate(FinalTime,TYear, TMonth,TDay);
FYear:=Integer(TYear);
FMonth:=Integer(TMonth);
FDay:=Integer(TDay); end;
NetApiBufferFree(Buffer);
end;
procedure AnsyTime(const DatabaseName:string);
var
td: _SYSTEMTIME;
ft: FILETIME;
begin
{ DONE -oKingron -cOther : 同步服务器时间 }
with TQuery.Create(Self) do
try
DatabaseName:=DatabaseName;
SQL.Clear;
SQL.Text := 'select td=getdate()';
Open;
DateTimeToSystemTime(FieldByName('td').AsDateTime, td);
SystemTimeToFileTime(td,ft);
LocalFileTimeToFileTime(ft,ft);
FileTimeToSystemTime(ft,td);
SetSystemTime(td);
finally
Free;
end;
end;
type
TIME_OF_DAY_INFO=record
tod_elapsedt:DWORD;
tod_msecs:dword;
tod_hours:dword;
tod_mins:dword;
tod_secs:dword;
tod_hunds:dword;
tod_timezone:longint;
tod_tinterval:dword;
tod_day:dword;
tod_month:dword;
tod_year:dword;
tod_weekday:dword;
end;procedure NetRemoteTOD(UncServerName:lptstr;var BufferPtr:TIME_OF_DAY_INFO);stdcall;external 'netapi.dll';
如果第一个参数为Nil,则从本地机器取得时间。
只能在NT上面使用!
很容易实现
不过似乎系统开销很大