Now
A downloadable game for Windows
#include <QCoreApplication>
#include <QNetworkAccessManager>
#include <QNetworkReply>
#include <QNetworkRequest>
#include <QDateTime>
#include <QTimer>
#include <QTextStream>
void fetchNetworkTime() {
QNetworkAccessManager *manager = new QNetworkAccessManager();
QObject::connect(manager, &QNetworkAccessManager::finished, [](QNetworkReply* reply) {
if (reply->error() == QNetworkReply::NoError) {
QString data = reply->readAll();
// 假设获取到的时间数据格式为 "yyyy-MM-ddTHH:mm:ssZ"
QDateTime dateTime = QDateTime::fromString(data, Qt::ISODate);
QTime time = dateTime.time();
QDate date = dateTime.date();
QTextStream(stdout) << "Network Time: " << time.toString() << "\n";
QTextStream(stdout) << "Network Date: " << date.toString() << "\n";
} else {
QTextStream(stdout) << "Error: " << reply->errorString() << "\n";
}
reply->deleteLater();
});
QNetworkRequest request(QUrl("http://worldtimeapi.org/api/timezone/Etc/UTC"));
manager->get(request);
}
int main(int argc, char *argv[]) {
QCoreApplication a(argc, argv);
QTimer::singleShot(0, &fetchNetworkTime);
return a.exec();
}
Leave a comment
Log in with itch.io to leave a comment.