栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > C/C++/C#

【C++ Builder】年/月/日的计算

C/C++/C# 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

【C++ Builder】年/月/日的计算

1.计算日期

代码如下(示例):

//---------------------------------------------------------------------------
void __fastcall TForm1::Label1Click(TObject *Sender)
{
	TDate tomorrow = IncDay(Now()); //计算明天的日期  	IncDay 返回增加天数的日期。
	this->Label1->Caption = tomorrow.FormatString("yyyy/mm/dd");
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Label2Click(TObject *Sender)
{
	TDate dayAfterNext = IncDay(Now(), 2);//计算后天的日期,注意参数为2.
	this->Label2->Caption = dayAfterNext.FormatString("yyyy/mm/dd");
}
2.计算月

代码如下(示例):

//---------------------------------------------------------------------------
void __fastcall TForm1::Label3Click(TObject *Sender)
{
	TDate nextMonth = IncMonth(Now()); //IncMonth 返回月数递增的日期。
	this->Label3->Caption = nextMonth.FormatString("yyyy/mm/dd");
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Label4Click(TObject *Sender)
{
	TDate monthAfterNext = IncMonth(Now(), 2);
	this->Label4->Caption = monthAfterNext.FormatString("yyyy/mm/dd");
}
2.计算年

代码如下(示例):

//---------------------------------------------------------------------------
void __fastcall TForm1::Label5Click(TObject *Sender)
{
	TDate nextYear = IncYear(Now()); //IncYear 返回递增年数的日期,第二年。
	this->Label5->Caption = nextYear.FormatString("yyyy/mm/dd");
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Label6Click(TObject *Sender)
{
	TDate yearNextAfter = IncYear(Now(), 2);//第三年
	this->Label6->Caption = yearNextAfter.FormatString("yyyy/mm/dd");
}
转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/1004807.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号