如何更改系统日期?(0分)

  • 主题发起人 chinargb
  • 开始时间
C

chinargb

Unregistered / Unconfirmed
GUEST, unregistred user!
如何更改系统日期?
 
贴段HUBDOG.CHM中的代码给你:
  日期函数Now()、Date()、Time()大家都用得多了,这些函数是读取系统日期时间的。可是遇到需要改变操作系统的时间时,他们就一点办法也没有,而Delphi4又没有提供相关的函数,所以只好求助于API函数SetSystemTime(SystemTime);无奈他要求的变量SystemTime太古怪了,属于TSystemTime,需要经过转换才可以得到,所以举例如下:
  1、定义变量
var SystemTime: TSystemTime;
  2、转换日期
DateTimeToSystemTime(StrToDatetime('1999-09-01 11:12:12' ),SystemTime);
  3、改变系统日期
SetSystemTime(SystemTime);
  到此系统日期已经改变,可是由于API函数SetSystemTime()本身存在的BUG,在你改变系统日期以后,等待一会,你会看到系统的日期是对的,可是时间却错了,并不是我们设定的11:12:12,这样的问题看来需要微软才能解决了
///////////////////////////////////////////
{ SetDate sets the current date in the operating system. Valid }
{ parameter ranges are: Year 1980-2099, Month 1-12 and Day }
{ 1-31. If the date is not valid, the function call is ignored. }
procedure SetDate(Year, Month, Day: Word); assembler;
asm
MOV CX,Year
MOV DH,BYTE PTR Month
MOV DL,BYTE PTR Day
MOV AH,2BH
INT 21H
end;

{ SetTime sets the time in the operating system. Valid }
{ parameter ranges are: Hour 0-23, Minute 0-59, Second 0-59 and }
{ Sec100 (hundredths of seconds) 0-99. If the time is not }
{ valid, the function call is ignored. }
procedure SetTime(Hour, Minute, Second, Sec100: Word); assembler;
asm
MOV CH,BYTE PTR Hour
MOV CL,BYTE PTR Minute
MOV DH,BYTE PTR Second
MOV DL,BYTE PTR Sec100
MOV AH,2DH
INT 21H
end;

function SetSystemDateTime(Year, Month, Day, Hour, Minute, Second: word): integer; export;
begin
SetDate(Year, Month, Day);
SetTime(Hour, Minute + 1, Second, 0);
result := 1;
end;

 
靠,一分都舍不得。人混成你这样,也挺难得的。
 
赫赫! 时间过久,强制结束!!!
 
顶部