Delphi編程實現獲取月份的最後一天,通過選擇日期後,會很方便的得出指定指定月份的最後一天是幾月幾號,在一些大型的Dlephi信息統計系統中,時間的各方面操作都使用廣泛,這個只是其中之一的小功能,分享給Delphi新手們,請看代碼:
01
unit Unit1;
02
interface
03
uses
04
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
05
Dialogs, StdCtrls, ComCtrls;
06
type
07
TForm1 = class(TForm)
08
Button1: TButton;
09
DateTimePicker1: TDateTimePicker;
10
Label1: TLabel;
11
Label2: TLabel;
12
function md(dat:Tdate):TDate;
13
procedure Button1Click(Sender: TObject);
14
private
15
{ Private declarations }
16
public
17
{ Public declarations }
18
end;
19
var
20
Form1: TForm1;
21
implementation
22
{$R *.dfm}
23
procedure TForm1.Button1Click(Sender: TObject);
24
begin
25
md(DateTimePicker1.Date);
26
end;
27
function TForm1.md(dat: Tdate): TDate;
28
var
29
d,m,y:Word;
30
begin
31
DecodeDate(Incmonth(Dat,1),Y,M,D);
32
result:=EncodeDate(Y,M,1)-1;
33
Label1.Caption := '本月的最後一天是:'+DateToStr(result);
34
end;
35
end.
