【0】在工程文件中Application.Run语句之前加入下面语句,可不让主Form在运行时显示:
Application.ShowMainForm := False;
【1】显示设置时间的对话框
ShellExecute(Handle, 'open', 'control', 'date/time', nil, SW_SHOW);
【2】FormatDateTime('yyyy mmmm',MyDate) 返回如【2008 十二月】
【3】//获得日期 Date := Trunc( DateTime );
//获得时间 Time := Frac( DateTime );
【3】计算任意月份的天数
procedure TForm1.Button10Click(Sender: TObject);
function DaysInMonth(ADate:TDateTime):Integer;
var MyYear,MyMonth,MyDay : Word;
MyDayTable : TDayTable;
tmpBool : Boolean;
begin
DecodeDate(ADate, MyYear, MyMonth, MyDay);
tmpBool := IsLeapYear(MyYear);
MyDayTable := MonthDays[tmpBool];
Result := MyDayTable[MyMonth];
end;
var MyDate : TDateTime; tmpStr : String; tmpInt : Integer;
begin
MyDate := strToDateTime('2003-12-01');
tmpStr := FormatDateTime('yyyy mmmm',MyDate);
tmpInt := DaysInMonth(MyDate);
ShowMessage(tmpStr + ' 有 ' + IntToStr(tmpInt) + 'ìì');
end;
【3】改变系统时间
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;
本文地址:http://com.8s8s.com/it/it4819.htm