• <ins id="pjuwb"></ins>
    <blockquote id="pjuwb"><pre id="pjuwb"></pre></blockquote>
    <noscript id="pjuwb"></noscript>
          <sup id="pjuwb"><pre id="pjuwb"></pre></sup>
            <dd id="pjuwb"></dd>
            <abbr id="pjuwb"></abbr>
            Cpper
            C/C++高級(jí)工程師 Android高級(jí)軟件工程師 IT集成工程師 音頻工程師 熟悉c,c++,java,c#,py,js,asp等多種語(yǔ)言 程序猿
            具體如下代碼,不贅述
            #ifndef WEBTIMEGET_H
            #define WEBTIMEGET_H
            #include 
            <QString>
            #include 
            <QVector>
            #include 
            <QObject>
            #include 
            <QDateTime>
            #include 
            <QtNetwork/QUdpSocket>

            class webTimeGetter : public QObject
            {
                Q_OBJECT
            public:        
                webTimeGetter();
                
            virtual ~webTimeGetter();
            public slots:    
                
            void readingData();
                
            void connectSucess();   
                
            void tryGet();
            private:    
                QVector
            <QString> hostList;
                QUdpSocket
            *      udpsocket;
                QDateTime        time;
            };

            #endif
            //! ccsdu2004

            #include <iostream>
            #include 
            "webTimeGetter.h"

            webTimeGetter::webTimeGetter()
            {
                hostList.push_back(
            "time.windows.com");
                hostList.push_back(
            "time.nist.gov");
                udpsocket 
            = new QUdpSocket(this);
                connect(udpsocket,SIGNAL(connected()),
            this,SLOT(connectSucess()));
                connect(udpsocket,SIGNAL(readyRead()),
            this,SLOT(readingData()));
            }

            webTimeGetter::
            ~webTimeGetter()
            {
            }

            void webTimeGetter::readingData()
            {
                QByteArray newTime;
                QDateTime epoch(QDate(
            190011));
                QDateTime unixStart(QDate(
            197011));
                
            do
                {
                    newTime.resize(udpsocket
            ->pendingDatagramSize());
                    udpsocket
            ->read(newTime.data(), newTime.size());
                }
            while(udpsocket->hasPendingDatagrams());
                QByteArray TransmitTimeStamp ;
                TransmitTimeStamp
            =newTime.right(8);
                quint32 seconds
            =TransmitTimeStamp[0];
                quint8 temp
            =0;
                
            for(int j=1;j<=3;j++)
                {
                    seconds
            =seconds<<8;
                    temp
            =TransmitTimeStamp[j];
                    seconds
            =seconds+temp;
                }
                
                time.setTime_t(seconds
            -epoch.secsTo(unixStart));
                std::cout
            <<time.date().year()<<std::endl;
                std::cout
            <<time.date().month()<<std::endl;
                std::cout
            <<time.date().day()<<std::endl;
                std::cout
            <<time.time().hour()<<std::endl;
                std::cout
            <<time.time().minute()<<std::endl;
                
                udpsocket
            ->disconnectFromHost();
                udpsocket
            ->close();
            }

            void webTimeGetter::connectSucess()
            {
                qint8 LI
            =0;
                qint8 VN
            =3;
                qint8 MODE
            =3;
                qint8 STRATUM
            =0;
                qint8 POLL
            =4;
                qint8 PREC
            =-6;
                QDateTime epoch(QDate(
            1900,1,1));
                qint32 second
            =quint32(epoch.secsTo(QDateTime::currentDateTime()));
                qint32 temp
            =0;
                QByteArray timeRequest(
            480);
                timeRequest[
            0]=(LI <<6| (VN <<3| (MODE);
                timeRequest[
            1]=STRATUM;
                timeRequest[
            2]=POLL;
                timeRequest[
            3]=PREC & 0xff;
                timeRequest[
            5]=1;
                timeRequest[
            9]=1;
                timeRequest[
            40]=(temp=(second&0xff000000)>>24);
                temp
            =0;
                timeRequest[
            41]=(temp=(second&0x00ff0000)>>16);
                temp
            =0;
                timeRequest[
            42]=(temp=(second&0x0000ff00)>>8);
                temp
            =0;
                timeRequest[
            43]=((second&0x000000ff));
                udpsocket
            ->flush();
                udpsocket
            ->write(timeRequest);
                udpsocket
            ->flush();
            }   

            void webTimeGetter::tryGet()
            {
                udpsocket
            ->connectToHost(hostList.at(0),123);
            }
            posted on 2012-07-24 22:42 ccsdu2009 閱讀(2610) 評(píng)論(0)  編輯 收藏 引用 所屬分類: QT編程
             
            久久精品国产亚洲精品| 久久精品中文闷骚内射| 久久偷看各类wc女厕嘘嘘| 欧美亚洲国产精品久久久久| 色综合久久综精品| 久久免费国产精品一区二区| 一本一本久久A久久综合精品 | 久久精品国产久精国产一老狼| 久久AAAA片一区二区| 国产 亚洲 欧美 另类 久久| 国产精品久久国产精品99盘 | 精品精品国产自在久久高清| 欧美va久久久噜噜噜久久| 人妻精品久久无码专区精东影业 | 久久综合久久综合亚洲| 久久综合亚洲色一区二区三区| 亚洲伊人久久成综合人影院 | 久久精品国产半推半就| 国产精品gz久久久| 久久婷婷人人澡人人| 久久亚洲日韩看片无码| 久久精品免费全国观看国产| 亚洲午夜久久久久久久久电影网| 中文字幕热久久久久久久| 精品久久久久久国产潘金莲 | 久久99国产精品成人欧美| 一级做a爰片久久毛片看看| 一本色道久久88精品综合| 狠狠色丁香久久综合五月| 久久国产美女免费观看精品| 2020久久精品亚洲热综合一本| 日本强好片久久久久久AAA| 精品久久久久久综合日本| 久久亚洲欧洲国产综合| 99久久免费国产特黄| 人人狠狠综合久久亚洲| 久久久精品人妻一区二区三区蜜桃 | 久久亚洲美女精品国产精品| 久久精品无码一区二区三区免费| 久久久久久精品免费看SSS| 久久精品9988|