C++ Builder 参考手册 ➙ System::Dateutils ➙ StartOfAWeek
某一年的某一周的开始时间 (ISO 8601),
这一年的这一周星期一 00:00:00.000 或这周指定的星期几的开始时间 00:00:00.000
头文件:#include <System.DateUtils.hpp>
命名空间:System::Dateutils
函数原型:
System::TDateTime __fastcall StartOfAWeek(
const System::Word AYear,
const System::Word AWeekOfYear,
const System::Word ADayOfWeek = 1);
参数:
- AYear:年,1 - 9999;
- AWeekOfYear:这一年的第几周,1 - 53;
- ADayOfWeek:这一周的星期几,默认值 1;1 = 星期一,2 = 星期二,……7 = 星期日;
返回值:
- AYear 年的第 AWeekOfYear 周的星期 ADayOfWeek 的开始时间,这一天的 00:00:00.0000;
• 这个函数使用 ISO 8601 国际标准,中国使用这个标准;
• 一年有多少周请参考 WeeksInYear 或 WeeksInAYear;周的规则请参考 IsValidDateWeek 和 IsValidDateMonthWeek;
• 获取某个日期时间是这一年的第几周可以使用函数 WeekOf 或 WeekOfTheYear; - 比较函数 StartOfAWeek 和 StartOfTheWeek:
• StartOfAWeek 的参数是整数年、第几周、星期几;这个函数可以获取这一周每一天的开始时间,不限于星期一;
• StartOfTheWeek 的参数是日期时间,这个函数只获取这一周星期一的开始时间。
例:
#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));
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 ➙ StartOfAWeek