【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;