C++ Builder 参考手册 ➙ System::Sysutils ➙ DecodeDateFully
从日期时间类型数值里面解析出年、月、日、星期、是否闰年
头文件:#include <System.SysUtils.hpp>
命名空间:System::Sysutils
函数原型:
bool __fastcall DecodeDateFully(const System::TDateTime DateTime, System::Word &Year, System::Word &Month, System::Word &Day, System::Word &DOW);
参数:
- DateTime:日期时间类型变量;
- Year:返回年,1 ~ 9999
- Month:返回月,1 ~ 12
- Day:返回日,1 ~ 31
- DOW:返回星期,1 ~ 7,美国习惯 (1:星期日,2:星期一,3:星期二,……,7:星期六)
返回值:
- 是否闰年:true 闰年,false 不是闰年;
- 解析结果通过参数 Year, Month, Day, DOW 返回。
例:
void __fastcall TForm1::Button1Click(TObject *Sender)
{
const wchar_t *DayNames[] = { L"星期日", L"星期一", L"星期二", L"星期三", L"星期四", L"星期五", L"星期六",};
System::TDateTime dt = Sysutils::Now();
unsigned short uYear, uMonth, uDay, uDOW;
bool bIsLeapYear = Sysutils::DecodeDateFully(dt, uYear, uMonth, uDay, uDOW);
UnicodeString s;
s.sprintf(L"今天日期:%u 年 %u 月 %u 日,%s,今年%s闰年", uYear, uMonth, uDay, DayNames[uDOW-1], bIsLeapYear?L"是":L"不是");
Memo1->Lines->Add(s);
}
运行结果:
运行结果相关:
- 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 参考手册 ➙ System::Sysutils ➙ DecodeDateFully
网友评论