DateTimePicker1.date:=StartofTheMonth(Now);//獲取了本月第一天
DateTimePicker2.date:=EndOfTheMonth(Now);//獲取了本月最后一天
當DateTimePicker1改變了,例如,選擇了3月15日,那么DateTimePicker2就要是3月31日。如何做到?
就是DateTimePicker2永遠是月底的最后一天。就是根據DateTimePicker1的選擇決定是哪個月的最后一天。
uj5u.com熱心網友回復:
uj5u.com熱心網友回復:
procedure TForm1.Button1Click(Sender: TObject);function IIF(aCondition:Boolean;trueValue,falseValue:Variant):Variant;
begin
if aCondition then
Result:=trueValue
else
Result:=falseValue;
end;
var
iYear,iMonth:Integer;
sLastDay:String;
begin
//下個月的1號減1就是今月的最后一天
//12月的下個月是下一年的1月1日
iYear:=YearOf(DateTimePicker1.Date);
iMonth:=MonthOf(DateTimePicker1.Date);
sLastDay:=IntToStr(IIF(iMonth=12,iYear+1,iYear))+'-'+
IntToStr(IIF(iMonth=12,1,iMonth+1))+'-'+
'1';
sLastDay:=DateToStr(StrToDate(sLastDay)-1);
DateTimePicker2.Date:=StrToDate(sLastDay);
Application.MessageBox(PChar(Format('日期:%s的月底為%s',[DateToStr(DateTimePicker1.Date),sLastDay])),'提示');
end;
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/259349.html
標籤:語言基礎/算法/系統設計
上一篇:huffman解壓縮問題
