WeekOfTheMonth - C++ Builder

2022-08-08  本文已影响0人  玄坴

C++ Builder 参考手册System::DateutilsWeekOfTheMonth


这个日期时间在这一个月的第几周 (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);

参数:

返回值:


例:

#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));
}

运行结果:


相关:


C++ Builder 参考手册System::DateutilsWeekOfTheMonth

上一篇下一篇

猜你喜欢

热点阅读