C++ Builder 參考手冊(cè) ? System::Sysutils ? EncodeDate
由年稠曼、月、日生成日期時(shí)間類型數(shù)值
頭文件:#include <System.SysUtils.hpp>
命名空間:System::Sysutils
函數(shù)原型:
System::TDateTime __fastcall EncodeDate(System::Word Year, System::Word Month, System::Word Day);
參數(shù):
- Year:年况褪,1 ~ 9999
- Month:月箭启,1 ~ 12
- Day:日韩肝,1 ~ 31
返回值:
- 日期時(shí)間類型數(shù)值,日期為參數(shù)指定的年、月垒在、日,時(shí)間為 00:00:00扔亥;
- 如果參數(shù)指定的年场躯、月谈为、日無效,拋出 EConvertError 異常踢关。
例:2021年10月29日轉(zhuǎn)換為日期時(shí)間成功伞鲫,2021年2月29日轉(zhuǎn)換為日期時(shí)間失敗:
void __fastcall TForm1::Button1Click(TObject *Sender)
{
try
{
TDateTime dt = Sysutils::EncodeDate(2021, 10, 29);
Memo1->Lines->Add(FormatDateTime(L"yyyy/mm/dd", dt));
}
catch(Exception &e)
{
ShowMessage(L"轉(zhuǎn)換出錯(cuò):" + e.Message);
}
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Button2Click(TObject *Sender)
{
try
{
TDateTime dt = Sysutils::EncodeDate(2021, 2, 29);
Memo1->Lines->Add(FormatDateTime(L"yyyy/mm/dd", dt));
}
catch(Exception &e)
{
ShowMessage(L"轉(zhuǎn)換出錯(cuò):" + e.Message);
}
}
運(yùn)行結(jié)果:
相關(guān):
- System::Dateutils::DecodeDateTime
- System::Dateutils::EncodeDateTime
- System::Dateutils::TryEncodeDateTime
- System::Dateutils::DateTimeToUnix
- System::Dateutils::UnixToDateTime
- System::Dateutils::YearOf
- System::Dateutils::MonthOf
- System::Dateutils::DayOf
- System::Dateutils::DayOfTheWeek
- System::Dateutils::DayOfTheMonth
- System::Dateutils::DayOfTheYear
- System::Dateutils::HourOf
- System::Dateutils::MinuteOf
- System::Dateutils::SecondOf
- System::Dateutils::MilliSecondOf
- System::Dateutils
- System::Sysutils::DecodeDate
- System::Sysutils::DecodeDateFully
- System::Sysutils::DecodeTime
- System::Sysutils::EncodeDate
- System::Sysutils::EncodeTime
- System::Sysutils::TryEncodeDate
- System::Sysutils::TryEncodeTime
- System::Sysutils::TryStrToDate
- System::Sysutils::TryStrToDateTime
- System::Sysutils::TryStrToTime
- System::Sysutils::FormatDateTime
- System::Sysutils::CurrentYear
- System::Sysutils::Now
- System::Sysutils::Date
- System::Sysutils::Time
- System::Sysutils
C++ Builder 參考手冊(cè) ? System::Sysutils ? EncodeDate