以下是輸入年月日來實現的,妳可以通過界面輸入控制上加上默認的日這個值即可.
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;
type
TForm1 = class(TForm)
Edit1: TEdit;
Edit2: TEdit;
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
function GetCurrDay(CurrDate: TDateTime): Integer;
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
function Tform1.GetCurrDay(CurrDate: TDateTime): Integer;
var
Year,Month,Day:word;
TempDate : TDateTime;
begin
DecodeDate(CurrDate,Year,Month,Day);
if Month=12 then
Result := 30
else
begin
TempDate:=EncodeDate(Year,Month+1,1)-1;
DecodeDate(TempDate,Year,Month,Day);
Result:=Day;
end;
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
Edit2.text:=IntToStr(GetCurrDay(StrToDateTime(Edit1.Text)));
end;
end.