SOS:如何更改系统时间???(急急...)(100分)

  • 主题发起人 主题发起人 程旭
  • 开始时间 开始时间

程旭

Unregistered / Unconfirmed
GUEST, unregistred user!
本人查遍了delphi 中关于时间的函数,没有找到。
各位帮帮忙吧!!!
 
抄袭如下:
设置一个TSystemTime变量,再调用SetSystemTime函数即可。
例:
procedure SetTime;
Var
MyTime:TSystemTime;
begin
myTime.wyear:='1999';
myTime.wmontt:='6';
myTime.wday:='12';
SetSystemTime(MyTime);
end;
 
您需要使用SetSystemTime Win32API
 
呵呵, 大家都在这里抓分哪!
 
不对吧!
SystemTime中的结构可全不是字符串呀!
正确的程序应该这样Var
procedure SetTime;
Var
MyTime:TSystemTime;
begin
myTime.wyear := 1999;
myTime.wmonth := 6;
myTime.wday := 12;
SetSystemTime(MyTime);
end;

 
调试通过, :)
 
pegasus,可以执行,但怎么不见系统时间改变呢??
 
正是越忙越错 :
procedure SetTime;
Var
MyTime:TSystemTime;
begin
myTime.wyear := 1999;
myTime.wmonth := 6;
myTime.wday := 12;
SetlocalTime(MyTime);
end;
 
是不是在NT下面?需要获得SE_SETSYSTEMTIME_NAME的权限
请参见在NT下面如何ShutDown机器
 
BOOL SetSystemTime(
CONST SYSTEMTIME *lpSystemTime // address of system time to set
);

typedef struct _SYSTEMTIME { // st
WORD wYear;
WORD wMonth;
WORD wDayOfWeek;
WORD wDay;
WORD wHour;
WORD wMinute;
WORD wSecond;
WORD wMilliseconds;
} SYSTEMTIME;

Members
wYear
Specifies the current year.
wMonth
Specifies the current month;
January = 1, February = 2, and so on.
wDayOfWeek
Specifies the current day of the week;
Sunday = 0, Monday = 1, and so on.
wDay
Specifies the current day of the month.
wHour
Specifies the current hour.
wMinute
Specifies the current minute.
wSecond
Specifies the current second.
wMilliseconds
Specifies the current millisecond.
.
the program is here!!
void __fastcall TForm1::Button1Click(TObject *Sender)
{
TSystemTime *lpSystemTime = new TSystemTime;
try{
lpSystemTime->wYear = 1994;
lpSystemTime->wMonth = 1;
lpSystemTime->wDayOfWeek = 1;
lpSystemTime->wDay = 1;
lpSystemTime->wHour = 12;
lpSystemTime->wMinute = 10;
lpSystemTime->wSecond = 10;
lpSystemTime->wMilliseconds = 10;*/
if (!SetSystemTime(lpSystemTime))
ShowMessage("error");
}
catch(Exception &E) {
ShowMessage(E.Message);
return;
}
delete lpSystemTime;
}
 
thanks everyone!!
 
thanks everyone!!


 
在清华的BBS网站上专门有一篇这样的文章,如果你找不到的话请MAIL(XIN78@263.NET)我,我再找篇文章发给你.
提醒:在设置系统日期时一定要有异常保护;NT环境下没有这个权限.
 
多人接受答案了。
 
后退
顶部