⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ntptime.h

📁 linux程序
💻 H
字号:
// NtpTime.h: interface for the CNtpTime class.
//
//////////////////////////////////////////////////////////////////////
#ifndef _NTP_TIME_H_
#define _NTP_TIME_H_
#include "OSHead.h"
#include "NtpStruct.h"

//Helper class to encapulate NTP time stamps
#ifdef __REDHATLINUX__
#include <time.h>
#include <sys/time.h>
typedef long long SInt64;
typedef unsigned long long UInt64;

typedef struct _SYSTEMTIME {
    unsigned short wYear;
    unsigned short wMonth;
    unsigned short wDayOfWeek;
    unsigned short wDay;
    unsigned short wHour;
    unsigned short wMinute;
    unsigned short wSecond;
    unsigned short wMilliseconds;
} SYSTEMTIME,*PSYSTEMTIME,*LPSYSTEMTIME;;

Bool8 GetSystemTime(SYSTEMTIME *st);
Bool8 SetSystemTime(SYSTEMTIME st);

#endif

class CNtpTime
{
public:
    //Constructors / Destructors
    CNtpTime();
    CNtpTime(const CNtpTime& time);
    CNtpTime(CNtpTimePacket& packet);
    CNtpTime(const SYSTEMTIME& st);

    //General functions
    CNtpTime& operator=(const CNtpTime& time);
    double operator-(const CNtpTime& time) const;
    CNtpTime operator+(const double& timespan) const;
    operator SYSTEMTIME() const;
    
    operator CNtpTimePacket() const;
    // operator unsigned __int64() const { return m_Time; };
    //operator unsigned long_long() const { return m_Time; };
    unsigned long Seconds() const;
    unsigned long Fraction() const;
    unsigned long long GetTimeLen(){return m_Time;}
    //Static functions
    static CNtpTime GetCurrentTime();

    static unsigned long MsToNtpFraction(unsigned short wMilliSeconds);
    static unsigned short NtpFractionToMs(unsigned long dwFraction);
    static double NtpFractionToSecond(unsigned long dwFraction);

    protected:
    //Internal static functions and data
    static long GetJulianDay(unsigned short Year, unsigned short Month, unsigned short Day);
    static void GetGregorianDate(long JD, unsigned short& Year, unsigned short& Month, unsigned short& Day);
    static unsigned long m_MsToNTP[1000];

    //The actual data
    // unsigned __int64 m_Time;
    // unsigned long long m_Time;
    UInt64 m_Time;
};


#endif 

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -