C++ Builder 参考手册 ➙ System::Dateutils ➙ StartOfADay
某一年的某一天的开始时间,
这一年的第几天的开始时间 (00:00:00.000),
这个年、月、日的开始时间 (00:00:00.000)
头文件:#include <System.DateUtils.hpp>
命名空间:System::Dateutils
函数原型:
System::TDateTime __fastcall StartOfADay(
const System::Word AYear,
const System::Word ADayOfYear);
System::TDateTime __fastcall StartOfADay(
const System::Word AYear,
const System::Word AMonth,
const System::Word ADay);
参数:
- AYear:年,1 - 9999;
- AMonth:月,1 - 12;
- ADay:日,1 - 31;
- ADayOfYear:这一年的几天,1 - 366;
返回值:
- AYear 年的第 ADayOfYear 天的开始时间 (00:00:00.000) 或
AYear 年 AMonth 月 ADay 日的开始时间 (00:00:00.000); - 可以使用 DayOfTheYear 获取一个日期时间是这一年的第几天;
使用 StartOfADay 和 EndOfADay 获取这一年的第几天的日期和时间; -
StartOfTheDay 和 StartOfADay 的区别:
• StartOfTheDay 的参数是一个日期时间;
• StartOfADay 的参数是年、月、日 或年和这一年的第几天;
如果日期相同,这两个函数的返回值相同。
例:
#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", StartOfTheDay(dt)));
Memo1->Lines->Add(L"今天结束 " + FormatDateTime(L"yyyy/mm/dd hh:nn:ss.zzz", EndOfTheDay(dt)));
unsigned short iYear = Dateutils::YearOf(dt);
unsigned short iDoY = Dateutils::DayOfTheYear(dt);
Memo1->Lines->Add(String().sprintf(L"今天是 %d年 的 第%d天", iYear, iDoY));
Memo1->Lines->Add(L"今天开始 " + FormatDateTime(L"yyyy/mm/dd hh:nn:ss.zzz", StartOfADay(iYear, iDoY)));
Memo1->Lines->Add(L"今天结束 " + FormatDateTime(L"yyyy/mm/dd hh:nn:ss.zzz", EndOfADay(iYear, iDoY)));
unsigned short iMonth = Dateutils::MonthOf(dt);
unsigned short iDay = Dateutils::DayOf(dt);
Memo1->Lines->Add(String().sprintf(L"今天是 %d年%d月%d日", iYear, iMonth, iDay));
Memo1->Lines->Add(L"今天开始 " + FormatDateTime(L"yyyy/mm/dd hh:nn:ss.zzz", StartOfADay(iYear, iMonth, iDay)));
Memo1->Lines->Add(L"今天结束 " + FormatDateTime(L"yyyy/mm/dd hh:nn:ss.zzz", EndOfADay(iYear, iMonth, iDay)));
}
运行结果:
相关:
- System::Dateutils::DayOfTheYear
- 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 ➙ StartOfADay
网友评论