目录
背景
这里我只是举个栗子,如有雷同,纯粹巧合。
比如一套实时数据读取系统,他会把数据读取到数据库,可能1分钟写入数据库一次,可能1s,可能5分钟。这里面经常会读取到错误数据。
这里可以通过当天的时间戳,把目前应该读取多少个数据记录下来,再到数据库里面查询,最后在处理数据异常的点,这样就避免了读取错误点后,直接停止的现象
演示
这里用Qt举个例子,每5分钟采集一个点:
程序运行截图如下:
程序结构如下:
关键代码:
void Widget::timerEvent(QTimerEvent *event)
{
Q_UNUSED(event)
uint currentDataInt = QDateTime::fromString(QDateTime::currentDateTime().toString("yyyy-M-dd"), "yyyy-M-dd").toTime_t();
uint currentTimeInt = QDateTime::currentDateTime().toTime_t();
qDebug() << "当天: " << currentDataInt;
qDebug() << "现在: " << currentTimeInt;
qDebug() << "目前写入点:" << (currentTimeInt - currentDataInt)/300;
qDebug() << "-------------华丽的分割线-------------";
}
程序打包下载地址: