C++ Builder 參考手冊 ? System::Dateutils ? SecondOfTheMonth
這個日期時間在這一個月的第幾秒鐘
頭文件:#include <System.DateUtils.hpp>
命名空間:System::Dateutils
函數(shù)原型:
unsigned __fastcall SecondOfTheMonth(const System::TDateTime AValue);
參數(shù):
- AValue:日期時間類型變量;
返回值:
- 返回值為 AValue 日期時間在這個月的第幾秒鐘匕争;
- 另外一個函數(shù) SecondOfTheYear 是一個日期時間在這一年的第幾秒鐘暂幼。
例:用兩種方法計算現(xiàn)在是本月的第幾秒鐘:1:用函數(shù) SecondOfTheMonth颓芭;2:利用兩個日期相減為雙精度浮點數(shù)的天數(shù)計算秒數(shù):
#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));
Memo1->Lines->Add(String().sprintf(L"現(xiàn)在是本月的第 %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; // 現(xiàn)在時間距離本月 1 日的天數(shù)失球,小數(shù)蟹漓,例如 0.5 為 12 小時
unsigned int uSeconds = lfDays * 24 * 60 * 60;
Memo1->Lines->Add(String().sprintf(L"現(xiàn)在是本月的第 %u 秒鐘", uSeconds));
}
運行結(jié)果:
相關:
- 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