Created
November 19, 2015 07:08
-
-
Save Mandar-Shinde/2e1e2549d8bf9755bf6a to your computer and use it in GitHub Desktop.
Qt Set Datetime
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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