QDateTime ts = QDateTime::currentDateTimeUtc();
QDateTime t1 = ts.addSecs(-5);
QDateTime t2 = ts.addSecs(5);
QVector<QDateTime> timeline;
int boo[] = {1,2,3,4,5,6};
foreach(int a, boo)
{
timeline.append(t1.addSecs(a));
}
QDateTime nearestTimestamp = QDateTime.fromMSecsSinceEpoch(0);
qint64 nearestRange = 999999999;
foreach(const QDateTime & curr, timeline)
{
qint64 range = qAbs(curr.msecsTo(ts));
if(range < nearestRange)
{
nearestRange = range;
nearestTimestamp = curr;
}
}