C++ Builder 參考手冊 ? System::Dateutils ? WeekOfTheMonth
這個日期時間在這一個月的第幾周 (ISO 8601)
頭文件:#include <System.DateUtils.hpp>
命名空間:System::Dateutils
函數(shù)原型:
System::Word __fastcall WeekOfTheMonth(
const System::TDateTime AValue);
System::Word __fastcall WeekOfTheMonth(
const System::TDateTime AValue,
System::Word &AYear,
System::Word &AMonth);
參數(shù):
- AValue:日期時間類型變量缸兔;
- AYear:返回這個日期的年蚓挤,1 - 9999允坚;
- AMonth:返回這個日期的月,1 - 12胎食;
返回值:
- 返回值為 AValue 日期時間在 AYear 年 AMonth 月的第幾周 (ISO 8601),范圍 1 - 5肴颊;
- 一個月一共有 4 或 5 周奸例,這些周的分配規(guī)則請參考 IsValidDateWeek;
- 一年一共有 52 或 53 周赡模,有關(guān)一年有多少周請參考 WeeksInYear田炭;
- 可以使用函數(shù) WeekOfTheYear 獲取一個日期時間在一年的第幾周 。
例:
#include <System.DateUtils.hpp>
void __fastcall TForm1::Button1Click(TObject *Sender)
{
TDateTime dt = Sysutils::Now();
Memo1->Lines->Add(L"現(xiàn)在時間 " + 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));
}
運行結(jié)果:
相關(guān):
- 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