C++ Builder 参考手册 ➙ System::Dateutils ➙ WeekOfTheYear
这个日期时间在这一年的第几周 (ISO 8601)
头文件:#include <System.DateUtils.hpp>
命名空间:System::Dateutils
函数原型:
System::Word __fastcall WeekOfTheYear(const System::TDateTime AValue);
System::Word __fastcall WeekOfTheYear(const System::TDateTime AValue, System::Word &AYear);
参数:
- AValue:日期时间类型变量;
- AYear:返回这个日期的年,1 - 9999;
返回值:
- 返回值为 AValue 日期时间在这一年的第几周 (ISO 8601),范围 1 - 53
- 一年一共有 52 或 53 周,有关一年有多少周请参考 WeeksInYear,这些周的分配规则请参考 IsValidDateWeek;
- 比较函数 WeekOfTheYear 和 WeekOf:
• WeekOfTheYear:有可选参数 AYear 返回年,函数返回第几周;
• WeekOf:只返回第几周;
这两个函数的返回值相同。
例:
#include <System.DateUtils.hpp>
void __fastcall TForm1::Button1Click(TObject *Sender)
{
TDateTime dt = Sysutils::Now();
Memo1->Lines->Add(L"现在时间 " + FormatDateTime(L"yyyy/mm/dd hh:nn:ss.zzz", dt));
unsigned short iYear;
unsigned short iWeek = WeekOfTheYear(dt, iYear);
Memo1->Lines->Add(String().sprintf(L"今天是 %d 年的第 %d 周", iYear, iWeek));
TDateTime t0 = StartOfAWeek(iYear, iWeek);
TDateTime t1 = EndOfAWeek(iYear, iWeek);
Memo1->Lines->Add(L"这一周从 " + FormatDateTime(L"yyyy/mm/dd hh:nn:ss.zzz",t0)
+ L" 到 " + FormatDateTime(L"yyyy/mm/dd hh:nn:ss.zzz",t1));
}
运行结果:
相关:
- System::Dateutils::WeekOfTheMonth
- System::Dateutils::MonthOfTheYear
- System::Dateutils::WeekOfTheYear
- System::Dateutils::DayOfTheYear
- System::Dateutils::HourOfTheYear
- System::Dateutils::MinuteOfTheYear
- System::Dateutils::SecondOfTheYear
- System::Dateutils::MilliSecondOfTheYear
- System::Dateutils::DateOf
- System::Dateutils::DateTimeToUnix
- System::Dateutils::DayOf
- System::Dateutils::DayOfTheMonth
- System::Dateutils::DayOfTheWeek
- System::Dateutils::DayOfTheYear
- System::Dateutils::DecodeDateTime
- System::Dateutils::EncodeDateTime
- System::Dateutils::HourOf
- System::Dateutils::IsValidDateWeek
- System::Dateutils::MilliSecondOf
- System::Dateutils::MinuteOf
- System::Dateutils::MonthOf
- System::Dateutils::SecondOf
- System::Dateutils::TimeOf
- System::Dateutils::TryEncodeDateTime
- System::Dateutils::UnixToDateTime
- System::Dateutils::WeeksInYear
- System::Dateutils::YearOf
- System::Dateutils
- System::Sysutils::CurrentYear
- System::Sysutils::Date
- System::Sysutils::DecodeDate
- System::Sysutils::DecodeDateFully
- System::Sysutils::DecodeTime
- System::Sysutils::EncodeDate
- System::Sysutils::EncodeTime
- System::Sysutils::FormatDateTime
- System::Sysutils::Now
- System::Sysutils::Time
- System::Sysutils::TryEncodeDate
- System::Sysutils::TryEncodeTime
- System::Sysutils::TryStrToDate
- System::Sysutils::TryStrToDateTime
- System::Sysutils::TryStrToTime
- System::Sysutils
C++ Builder 参考手册 ➙ System::Dateutils ➙ WeekOfTheYear
网友评论