本文整理汇总了C++中NPT_TimeStamp::FromNanos方法的典型用法代码示例。如果您正苦于以下问题:C++ NPT_TimeStamp::FromNanos方法的具体用法?C++ NPT_TimeStamp::FromNanos怎么用?C++ NPT_TimeStamp::FromNanos使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类NPT_TimeStamp
的用法示例。
在下文中一共展示了NPT_TimeStamp::FromNanos方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: CheckDate
/*----------------------------------------------------------------------
| NPT_DateTime::ToTimeStamp
+---------------------------------------------------------------------*/
NPT_Result
NPT_DateTime::ToTimeStamp(NPT_TimeStamp& timestamp) const
{
// default value
timestamp.SetNanos(0);
// check bounds
NPT_Result result = CheckDate(*this);
if (NPT_FAILED(result)) return result;
// compute the number of days elapsed since 1900
NPT_UInt32 days = ElapsedDaysSince1900(*this);
// compute the number of nanoseconds
NPT_Int64 seconds = (NPT_Int64)days * (24*60*60) +
(NPT_Int64)m_Hours * (60*60) +
(NPT_Int64)m_Minutes * (60) +
(NPT_Int64)m_Seconds;
seconds -= (NPT_Int64)m_TimeZone*60;
// adjust to the number of seconds since 1900
seconds -= (NPT_Int64)NPT_SECONDS_PER_YEAR*70 +
(NPT_Int64)(17*NPT_SECONDS_PER_DAY); // 17 leap year between 1900 and 1970
timestamp.FromNanos(seconds * 1000000000 + m_NanoSeconds);
return NPT_SUCCESS;
}
示例2: epoch
/*----------------------------------------------------------------------
| NPT_System::GetCurrentTimeStamp
+---------------------------------------------------------------------*/
NPT_Result
NPT_System::GetCurrentTimeStamp(NPT_TimeStamp& now)
{
FILETIME time;
GetSystemTimeAsFileTime(&time);
ULARGE_INTEGER ltime;
ltime.LowPart = time.dwLowDateTime;
ltime.HighPart = time.dwHighDateTime;
/* convert to 64-bits 100-nanoseconds value */
ULONGLONG time64 = ltime.QuadPart;
time64 -= 116444736000000000; /* convert from the Windows epoch (Jan. 1, 1601) to the
* Unix epoch (Jan. 1, 1970) */
now.FromNanos(time64*100);
return NPT_SUCCESS;
}