//the calculation method of WWL begin
DecodeDate (dDate, AYear, AMonth, ADay);
DecodeDate (Now, AYear2 AMonth2, ADay2);
IYear:=YearsBetween (Now, dDate);
NMonth:=MonthsBetween (Now, dDate);
Nday:=DaysBetween (Now, dDate);
IYear:=nMonth div 12;//vary year
If nMonth> 12 then
AYear:=AYear + iYear;
DDate:=EncodeDate (AYear, AMonth, ADay);
NMonth:=MonthsBetween (Now, dDate);//differ in
IMonth:=nMonth;//the rest in
If nMonth<12 then
If nMonth<12 - AMonth then
AMonth:=AMonth + nMonth;
If nMonth> 12 - AMonth then
The begin
AMonth:=nMonth - (12 - AMonth);
If AMonth> 12 then
AMonth:=AMonth - 12;
AYear:=AYear + 1;
end;
DDate:=EncodeDate (AYear, AMonth, ADay);
IDay:=DaysBetween (Now, dDate);
If AYear> Then 3000
AYear:=AYear2;
If AMonth> 12 then=
AMonth:=0;
If ADay> 30 then
ADay:=0;
If iMonth<0 then
IMonth:=0;
If iDay<0 then
IDay:=0;
//the calculation method of WWL end
CodePudding user response:
You have a problem that:1, the number of days in not fixed, so, not sure X months,
2, only if from Now, backward, buckle throughout the year, after several days, and then promote the rest of the months, days,
CodePudding user response:
Algorithm should be such, more year, the first year difference, such as nYear, judgment conditions are & gt; Date=0, otherwise the pop-up error; In comparison, get nMonth, if in & gt; Days=0, a direct comparison; Otherwise if nYear & gt;=1, & lt; Date of 1 pop-up error;>=1, nYear minus 1, nMonth + 12; More days again, if nDay>=0, came to the conclusion that otherwise, nMonth - 1, nDay + last month, the number of days;CodePudding user response:
More days if negative, the same to determine month, year enough clasp, if judgment before disassembly (date) (month) (year), without judgmentCodePudding user response:
procedure TForm1. Button1Click (Sender: TObject);
Var
DDate: TDateTime;
AYear, AMonth, ADay, AYear2 AMonth2, ADay2: Word;
IYear, iMonth, iDay, nMonth nday: Integer;
The begin
DDate:=DateTimePicker1. DateTime;
If dDate & gt; Now then
Exit;
DecodeDate (dDate, AYear, AMonth, ADay);
DecodeDate (Now, AYear2 AMonth2, ADay2);
IYear:=AYear2 - AYear;
IMonth=AMonth2 - AMonth.
If iMonth & lt; 0 then
The begin
IYear:=iYear - 1;
IMonth: iMonth=+ 12;
end;
IDay:=ADay2 - ADay;
If iDay & lt; 0 then
The begin
IMonth: iMonth=1;
If iMonth & lt; 0 then
The begin
IYear:=iYear - 1;
IMonth: iMonth=+ 12;
IDay:=ADay2;
end;
end;
If (iYear=0) and (iMonth=0) then
IDay:=DaysBetween (Now, dDate);
Edit1. Text:=Format (" % d % d % d month day 'age, [iYear, iMonth, iDay]);
//iYear:=YearsBetween (Now, dDate);
//nMonth:=MonthsBetween (Now, dDate);
//nday:=DaysBetween (Now, dDate);
//iYear:=nMonth div 12;//vary year
//if nMonth & gt; 12 then
//AYear:=AYear + iYear;
//
//dDate:=EncodeDate (AYear, AMonth, ADay);
//nMonth:=MonthsBetween (Now, dDate);//differ in
//iMonth=nMonth;//the rest in
//
//if nMonth & lt; 12 then
//if nMonth & lt; 12 - AMonth then
//AMonth:=AMonth + nMonth;
//if nMonth & gt; 12 - AMonth then
//the begin
//
//AMonth:=nMonth - (12 - AMonth);
//if AMonth & gt; 12 then
//AMonth:=AMonth - 12;
//AYear:=AYear + 1;
//end;
//
//dDate:=EncodeDate (AYear, AMonth, ADay);
//
//iDay:=DaysBetween (Now, dDate);
//
//if AYear & gt; Then 3000
//AYear:=AYear2;
//
//if AMonth & gt; 12 then=
//AMonth:=0;
//if ADay & gt; 30 then
//ADay:=0;
//
//if iMonth & lt; 0 then
//iMonth=0;
//if iDay & lt; 0 then
//iDay:=0;
end;
CodePudding user response:
You read the code,,1, want to consider more than a specified date, the monthly number of cumulative
2, want to consider the number of days of month, February 26,27,28,29; Single and double month 30, 31 days;
3, the number of days during the month, and the actual unified,
CodePudding user response:
to make a toy out, after the test, a near perfectunit UnitMain;
Interface
USES the
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, DateUtils StdCtrls ComCtrls;
Type
TFormMain=class (TForm)
DateTimePicker1: TDateTimePicker;
For: TButton;
Edit1: TEdit;
Edit2: TEdit;
Label1: TLabel;
Label2: TLabel;
Label3: TLabel;
Procedure Button1Click (Sender: TObject);
Procedure MyGetLunarHolDay;
Private
{Private declarations}
Public
{Public declarations}
end;
Var
FormMain: TFormMain;
Implementation
USES DateCn UGL2NLdatae;
{$R *. DFM}
Procedure TFormMain. MyGetLunarHolDay;
Var
I: Integer;
S: a string;
The begin
S:=GetLunarHolDay (DateTimePicker1. Date);
If the s & lt;> "' then
Label2. Caption:=format (' solar terms: today [% s], [s])
The else
The begin
For I:=1 to 20 do
The begin
S:=GetLunarHolDay (DateTimePicker1. Date - I);
If the s & lt;> "' then
The begin
nullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnull