C++ Builder 参考手册 ➙ System::Dateutils ➙ SecondOfTheMonth
这个日期时间在这一个月的第几秒钟
头文件:#include <System.DateUtils.hpp>
命名空间:System::Dateutils
函数原型:
unsigned __fastcall SecondOfTheMonth(const System::TDateTime AValue);
参数:
- AValue:日期时间类型变量;
返回值:
- 返回值为 AValue 日期时间在这个月的第几秒钟;
- 另外一个函数 SecondOfTheYear 是一个日期时间在这一年的第几秒钟。
例:用两种方法计算现在是本月的第几秒钟:1:用函数 SecondOfTheMonth;2:利用两个日期相减为双精度浮点数的天数计算秒数:
#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(String().sprintf(L"现在是本月的第 %u 秒钟", SecondOfTheMonth(dt)));
unsigned short iYear = YearOf(dt); // 年
unsigned short iMonth = MonthOf(dt); // 月
TDateTime d0 = EncodeDate(iYear, iMonth, 1); // iYear 年 iMonth 月 1 日
double lfDays = dt - d0; // 现在时间距离本月 1 日的天数,小数,例如 0.5 为 12 小时
unsigned int uSeconds = lfDays * 24 * 60 * 60;
Memo1->Lines->Add(String().sprintf(L"现在是本月的第 %u 秒钟", uSeconds));
}
运行结果:
相关:
- 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::HourOfTheMonth
- System::Dateutils::HourOfTheYear
- System::Dateutils::IsValidDateMonthWeek
- System::Dateutils::IsValidDateWeek
- System::Dateutils::MilliSecondOf
- System::Dateutils::MilliSecondOfTheYear
- System::Dateutils::MinuteOf
- System::Dateutils::MinuteOfTheMonth
- 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 ➙ SecondOfTheMonth