/*---------------------------------------------------------------------- | 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; }
/*---------------------------------------------------------------------- | 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; }