EndOfAWeek - C++ Builder

C++ Builder 参考手册 ➙ System::Dateutils ➙ EndOfAWeek


某一年的某一周的结束时间 (ISO 8601),
这一年的这一周星期日 23:59:59.999 或这周指定的星期几的结束时间 23:59:59.999

头文件:#include
命名空间:System::Dateutils
函数原型:

System::TDateTime __fastcall EndOfAWeek(
    const System::Word AYear,
    const System::Word AWeekOfYear,
    const System::Word ADayOfWeek = 7);

参数:

  • AYear:年,1 - 9999;
  • AWeekOfYear:这一年的第几周,1 - 53;
  • ADayOfWeek:这一周的星期几,默认值 7;1 = 星期一,2 = 星期二,……7 = 星期日;

返回值:

  • AYear 年的第 AWeekOfYear 周的星期 ADayOfWeek 的结束时间,这一天的 23:59:59.999;
    • 这个函数使用 ISO 8601 国际标准 (中国使用这个标准);
    • 一年有多少周请参考 WeeksInYear 或 WeeksInAYear;周的规则请参考 IsValidDateWeek 和 IsValidDateMonthWeek;
    • 获取某个日期时间是这一年的第几周可以使用函数 WeekOf 或 WeekOfTheYear;
  • 比较函数 EndOfAWeek 和 EndOfTheWeek:
    • EndOfAWeek 的参数是整数年、第几周、星期几;这个函数可以获取这一周每一天的结束时间,不限于星期日;
    • EndOfTheWeek 的参数是日期时间,这个函数只获取这一周星期日的结束时间。

例:

#include 
void __fastcall TForm1::Button1Click(TObject *Sender)
{
    TDateTime dt = Sysutils::Now();
    Memo1->Lines->Add(L"现在时间 " + FormatDateTime(L"yyyy/mm/dd hh:nn:ss.zzz", dt));
    Memo1->Lines->Add(L"本周开始 " + FormatDateTime(L"yyyy/mm/dd hh:nn:ss.zzz", StartOfTheWeek(dt)));
    Memo1->Lines->Add(L"本周结束 " + FormatDateTime(L"yyyy/mm/dd hh:nn:ss.zzz", EndOfTheWeek(dt)));

    unsigned short iYear = Dateutils::YearOf(dt);
    unsigned short iWeek = Dateutils::WeekOf(dt);

    Memo1->Lines->Add(String().sprintf(L"今天是 %d年 的 第%d周", iYear, iWeek));
    Memo1->Lines->Add(L"本周开始 " + FormatDateTime(L"yyyy/mm/dd hh:nn:ss.zzz", StartOfAWeek(iYear,iWeek)));
    Memo1->Lines->Add(L"本周结束 " + FormatDateTime(L"yyyy/mm/dd hh:nn:ss.zzz", EndOfAWeek(iYear,iWeek)));

    Memo1->Lines->Add(L"本周二开始 " + FormatDateTime(L"yyyy/mm/dd hh:nn:ss.zzz", StartOfAWeek(iYear,iWeek,2)));
    Memo1->Lines->Add(L"本周二结束 " + FormatDateTime(L"yyyy/mm/dd hh:nn:ss.zzz", EndOfAWeek(iYear,iWeek,2)));
}

运行结果:


相关:

  • System::Dateutils::StartOfTheYear
  • System::Dateutils::EndOfTheYear
  • System::Dateutils::StartOfTheMonth
  • System::Dateutils::EndOfTheMonth
  • System::Dateutils::StartOfTheWeek
  • System::Dateutils::EndOfTheWeek
  • System::Dateutils::StartOfTheDay
  • System::Dateutils::EndOfTheDay
  • System::Dateutils::StartOfAYear
  • System::Dateutils::EndOfAYear
  • System::Dateutils::StartOfAMonth
  • System::Dateutils::EndOfAMonth
  • System::Dateutils::StartOfAWeek
  • System::Dateutils::EndOfAWeek
  • System::Dateutils::StartOfADay
  • System::Dateutils::EndOfADay
  • System::Dateutils::DaysInYear
  • System::Dateutils::DaysInAYear
  • System::Dateutils::DaysInMonth
  • System::Dateutils::DaysInAMonth
  • System::Dateutils::WeeksInYear
  • System::Dateutils::WeeksInAYear
  • System::Dateutils::WeekOf
  • System::Dateutils::WeekOfTheYear
  • System::Dateutils

C++ Builder 参考手册 ➙ System::Dateutils ➙ EndOfAWeek

你可能感兴趣的:(EndOfAWeek - C++ Builder)