Skip to content

Instantly share code, notes, and snippets.

@Mandar-Shinde
Created November 19, 2015 07:08
Show Gist options
  • Save Mandar-Shinde/2e1e2549d8bf9755bf6a to your computer and use it in GitHub Desktop.
Save Mandar-Shinde/2e1e2549d8bf9755bf6a to your computer and use it in GitHub Desktop.
Qt Set Datetime
#include <QCoreApplication>
#include <qdatetime.h>
#include <windows.h>
// QT 5.4 - Console Application
// (RUN AS ADMINISTRATOR)
//
int main(int argc, char *argv[])
{
QCoreApplication a(argc, argv);
// Datetime to be applied on system
//
QString date="2015-05-05 10:10:10";
QDateTime dt=QDateTime::fromString(date, "yyyy-MM-dd hh:mm:ss");
// WinAPI calls
SYSTEMTIME st;
GetSystemTime(&st);
st.wDay = dt.date().day();
st.wMonth = dt.date().month();
st.wYear = dt.date().year();
st.wHour = dt.time().hour();
st.wMinute = dt.time().minute();
st.wSecond = dt.time().second();
SetSystemTime(&st);
return a.exec();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment