Delphi完成讀取體系時光與日期完全實例。本站提示廣大學習愛好者:(Delphi完成讀取體系時光與日期完全實例)文章只能為提供參考,不一定能成為您想要的結果。以下是Delphi完成讀取體系時光與日期完全實例正文
本文講述了Delphi讀取體系時光與日期的完成辦法,起首設置各個控件用於顯示時光、讀取時光與設置時光。再添加以下代碼:
unit Unit1; interface uses Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls; type TForm1 = class(TForm) Button1: TButton; Memo1: TMemo; Button2: TButton; procedure Button1Click(Sender: TObject); procedure FormCreate(Sender: TObject); procedure Button2Click(Sender: TObject); private { Private declarations } public { Public declarations } end; var Form1: TForm1; implementation {$R *.DFM} uses ShellAPI; function SetSystemDateTime(Year, Month, Day, Hour, Minute, Second: word): integer; export; 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; 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; begin SetDate(Year, Month, Day); SetTime(Hour, Minute + 1, Second, 0); result := 1; end; procedure TForm1.Button1Click(Sender: TObject); var st : TSYSTEMTIME; begin //獲得體系時光 GetSystemTime(st); //顯示體系時光 Memo1.Lines.Add('體系時光 = ' + IntToStr(st.wmonth) + '/' + IntToStr(st.wDay) + '/' + IntToStr(st.wYear) + ' ' + IntToStr(st.wHour) + ':' + IntToStr(st.wMinute) + ':' + IntToStr(st.wSecond)); end; procedure TForm1.FormCreate(Sender: TObject); begin Memo1.Lines.Clear; end; procedure TForm1.Button2Click(Sender: TObject); var st: TSYSTEMTIME; begin DateTimeToSystemTime(StrToDatetime('2002-06-23 15:39:46' ),st); SetSystemTime(st); end; end.