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.