C++ Builder 参考手册 ➙ System::Dateutils ➙ WeekOfTheMonth
这个日期时间在这一个月的第几周 (ISO 8601)
头文件:#include <System.DateUtils.hpp>
命名空间:System::Dateutils
函数原型:
System::Word __fastcall WeekOfTheMonth(
const System::TDateTime AValue);
System::Word __fastcall WeekOfTheMonth(
const System::TDateTime AValue,
System::Word &AYear,
System::Word &AMonth);
参数:
- AValue:日期时间类型变量;
- AYear:返回这个日期的年,1 - 9999;
- AMonth:返回这个日期的月,1 - 12;
返回值:
- 返回值为 AValue 日期时间在 AYear 年 AMonth 月的第几周 (ISO 8601),范围 1 - 5;
- 一个月一共有 4 或 5 周,这些周的分配规则请参考 IsValidDateWeek;
- 一年一共有 52 或 53 周,有关一年有多少周请参考 WeeksInYear;
- 可以使用函数 WeekOfTheYear 获取一个日期时间在一年的第几周 。
例:
#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));
unsigned short iMonth;
iWeek = WeekOfTheMonth(dt, iYear, iMonth);
Memo1->Lines->Add(String().sprintf(L"今天是 %d 年 %d 月的第 %d 周", iYear, iMonth, iWeek));
}
运行结果:
相关:
- 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::HourOfTheYear
- System::Dateutils::IsValidDateMonthWeek
- System::Dateutils::IsValidDateWeek
- System::Dateutils::MilliSecondOf
- System::Dateutils::MilliSecondOfTheYear
- System::Dateutils::MinuteOf
- System::Dateutils::MinuteOfTheYear
- System::Dateutils::MonthOf
- System::Dateutils::MonthOfTheYear
- System::Dateutils::SecondOf
- System::Dateutils::SecondOfTheYear
- System::Dateutils::TimeOf
- System::Dateutils::TryEncodeDateTime
- System::Dateutils::UnixToDateTime
- System::Dateutils::WeekOfTheMonth
- System::Dateutils::WeekOfTheYear
- 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 ➙ WeekOfTheMonth
网友评论