评论

收藏

[其他] i.mx287学习笔记5-Time

网络安全 网络安全 发布于:2021-07-16 20:20 | 阅读数:586 | 评论:0

1.网络时间接口下面介绍几个常用的时间同步服务器的域名及IP地址:
域名    IP地址
time-a.nist.gov129.6.15.28
time-b.nist.gov129.6.15.29
time-a.timefreq.bldrdoc.gov 132.163.4.101
time-b.timefreq.bldrdoc132.163.4.102
time-c.timefreq.bldrdoc.gov132.163.4.103
utcnist.colorado.edu128.138.140.44
time.nist.gov192.43.244.18
time-nw.nist.gov 131.107.1.10
nist1.datum.com66.243.43.21
nist1-dc.glassey.com 216.200.93.8
nist1-ny.glassey.com208.184.49.9
nist1-sj.glassey.com207.126.98.204
nist1.aol-ca.truetime.com207.200.81.113
nist1.aol-va.truetime.com205.188.185.33
国家授时210.72.145.44

 
2.QT电脑端测试
DSC0000.png

源码
QStringList net_time;
  QTcpSocket *socket = new QTcpSocket();
  socket->connectToHost("time.nist.gov", 13);
  if (socket->waitForConnected())
  {
    if (socket->waitForReadyRead())
    {
      QString str(socket->readAll());
      str = str.trimmed();
      str = str.section(" ", 1, 2);
      qDebug() <<"Time  :"<< str;
    }
  }
  else
  {
    qDebug("Connected:err");
  }
  socket->close();
  delete socket;
DSC0001.png

3.显示系统时间初始化
QTimer *timer = new QTimer(this);
  connect(timer,SIGNAL(timeout()),this,SLOT(timerUpdate()));
  timer->start(1000);
显示:
void MainWindow::timerUpdate(void)
{
  QDateTime time = QDateTime::currentDateTime();
  QString str = time.toString("yyyy-MM-dd hh:mm:ss dddd");
  ui->label->setText(str);
}
效果:
DSC0002.png

4.开启定时器初始化
qsrand(time(0));
  startTimer(1000);
源码
void MainWindow::timerEvent(QTimerEvent *t)
{
  *t =*t;
  QString ab = QString::number(count);
  ui->label_2->setText(ab);
  count++;
}
效果,1秒自加一次
DSC0003.png

 

分享到: QQ好友和群QQ好友和群
评论

使用道具 举报