c/c++

WeekOfTheYear - C++ Builder

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

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


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

参数:

返回值:


例:

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

运行结果:


相关:


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

上一篇下一篇

猜你喜欢

热点阅读