TimeStampToMSecs - C++ Builder

C++ Builder 参考手册 ➙ System::Sysutils ➙ TimeStampToMSecs


时间戳转为毫秒数

头文件:#include
命名空间:System::Sysutils
函数原型:

System::Comp __fastcall TimeStampToMSecs(const TTimeStamp &TimeStamp);

参数:

  • TimeStamp:Sysutils::TTimeStamp 类型的时间戳,包含:
    • Date:天数,必须大于等于 0;
    • Time:毫秒数,范围:0 ~ 86399999;

返回值:

  • 毫秒,双精度浮点数 double 类型;如果天数或毫秒数小于0,或毫秒数大于等于 86400000,抛出 EConvertError 异常;
  • 返回值等于 TimeStamp.Date*86400000 + TimeStamp.Time,
    因为一天有 86400000 毫秒,所以天数乘以这个数值,而 TimeStamp.Time 是一天经过的毫秒数,所以 Time 的范围是 0 到 86400000-1 之间;
  • Sysutils::TTimeStamp 类型的时间戳主要用于系统内部的时间运算,而不是 UNIX 时间戳;
  • 日期时间转 UNIX 时间戳可以使用 System::Dateutils::DateTimeToUnix;
  • UNIX 时间戳转日期时间可以使用 System::Dateutils::UnixToDateTime。

例子:

void __fastcall TForm1::Button1Click(TObject *Sender)
{
    Sysutils::TTimeStamp ts;
    double ms;

    ts.Date = 1;
    ts.Time = 123;
    ms = TimeStampToMSecs(ts);
    Memo1->Lines->Add(ms);
    Memo1->Lines->Add(ts.Date*86400000 + ts.Time);

    ts.Date = 10;
    ts.Time = 12345678;
    ms = TimeStampToMSecs(ts);
    Memo1->Lines->Add(ms);
    Memo1->Lines->Add(ts.Date*86400000 + ts.Time);
}

运行结果:

运行结果

相关:

  • System::Sysutils::MSecsToTimeStamp
  • System::Sysutils::TimeStampToMSecs
  • System::Sysutils::DateTimeToTimeStamp
  • System::Sysutils::TimeStampToDateTime
  • System::Sysutils::TTimeStamp
  • System::Sysutils::DateTimeToFileDate
  • System::Sysutils::FileDateToDateTime
  • System::Sysutils::FileAge
  • System::Sysutils::FileGetDate
  • System::Sysutils::FileSetDate
  • System::Sysutils::DateToStr
  • System::Sysutils::TimeToStr
  • System::Sysutils::DateTimeToStr
  • System::Sysutils::DateTimeToString
  • System::Sysutils::FormatDateTime
  • System::Sysutils::StrToDate
  • System::Sysutils::StrToDateDef
  • System::Sysutils::StrToTime
  • System::Sysutils::StrToTimeDef
  • System::Sysutils::StrToDateTime
  • System::Sysutils::StrToDateTimeDef
  • System::Sysutils::FloatToDateTime
  • System::Sysutils::FormatSettings
  • System::Sysutils::TFormatSettings
  • System::Sysutils
  • System::Ioutils::TFile::GetLastWriteTime
  • System::Ioutils::TFile::GetLastAccessTime
  • System::Ioutils::TFile::GetCreationTime
  • System::Ioutils::TFile::SetLastWriteTime
  • System::Ioutils::TFile::SetLastAccessTime
  • System::Ioutils::TFile::SetCreationTime
  • System::Ioutils
  • System::Dateutils::DateTimeToUnix
  • System::Dateutils::UnixToDateTime
  • System::Dateutils
  • System::TDateTime
  • System::Comp
  • System

C++ Builder 参考手册 ➙ System::Sysutils ➙ TimeStampToMSecs
`

你可能感兴趣的:(TimeStampToMSecs - C++ Builder)