我需要找到一个给定日期满月的百分比,但我不知道如何计算。我试图这样做是错误的,因为今天的百分比约为96.9%。有人能看出我在我的Delphi代码做错了什么吗?
procedure TfrmLag.btnCalcClick(Sender: TObject);
var
whatDate : TDateTime; // Now;
lunarDays : Double; // 29.53058770576
lunarSecs : LongInt; // lunarDays * (24*60*60);
new2000 : TDateTime; // 6.1 2000 18:14
totalSecs : LongInt; // whatDate - new2000
currSecs : LongInt; // totalSecs MOD lunarSecs
currFrac : Double; // currSecs / lunarSecs
currDays : LongInt; // currFrac * lunarDays
perOfFull : Double;
begin
whatDate := Now;
lunarDays := 29.53058770576;
lunarSecs := Round(lunarDays * (24*60*60));
new2000 := EncodeDateTime(2000,1,6,18,14,00,000);
totalSecs := SecondsBetween(whatDate, new2000);
currSecs := totalSecs MOD lunarSecs;
currFrac := currSecs / lunarSecs;
currDays := Round(currFrac*lunarDays);
perOfFull := (100*currFrac);
lb.Items.Add('Date : '+FormatDateTime('dd.mm.yyyy hh:mm:ss',whatDate));
lb.Items.Add('Lunar days : '+IntToStr(lunarSecs));
lb.Items.Add('First full 2000 : '+FormatDateTime('dd.mm.yyyy hh:mm:ss',new2000));
lb.Items.Add('Total seconds : '+IntToStr(totalSecs));
lb.Items.Add('Current seconds : '+IntToStr(currSecs));
lb.Items.Add('Current fraction : '+FloatToStr(currFrac));
lb.Items.Add('Current days : '+IntToStr(currDays));
lb.items.Add('Percent of full : '+FloatToStr(perOfFull));
end;
1条答案
按热度按时间b1uwtaje1#
new2000
是2000年的第一个新月吧?如果是的话,这个代码应该计算正确。new2000
是满月,则只需在cos()
函数中删除-1
。这应该会给予你在
MoonPart
中可见的月亮部分和自上次新月以来的天数(包括分数)。