QDateTime without time zone, not working with timer or somenthing?
-
Hi, i'm new in qt and i need some answers for my question...
So.. I'm trying to get only date without time zone for my app...
I found in QT QDateTime but this get time zone too...
someone know how to do this?
sorry for my english, i'm not so good..
the code is:
@
QDateTime today = QDateTime::currentDateTime();
QDateTime tomorrow= today.addDays(1);
QString sql = "UPDATE agendamento SET data = ? WHERE data < ? AND regra >= 5";
QSqlQuery query = prepareQuery(sql);query.addBindValue(tomorrow); query.addBindValue(today.date());@
the result is : 2013-09-03 13:38:57.331
but I need: 2013-09-03 00:00:00Thanks for any help!
-
There are two static functions:
@QDateTime::currentDateTime(); // gives you the curent date and time for the timezone you are in
QDateTime::currentDateTimeUtc();//ignores the timezone and gives you the current Greenwich Mean Time@
That second function should do the trick.
PS: And if I misunderstood you and you actually only want to know the date, use QDate instead:
@QDate::currentDate();//gives you the current date@Alternatively:
@QDateTime::currentDateTime().date();//same as before@I suggest you take a look into the documentation. It's nice in there! ;)
PPS: Try to choose a more informative title for your thread next time, otherwise people might not read it.
-
thEClaw thanks for you support.. i dont know how to explain but thats not work...
I'm understand whats happens but.. for some reason not works..
I'm not sure why, but if make a difference I'm using signals and slots..
check the code:
@ connect(&_timer, SIGNAL(timeout()), this, SLOT(mostraHora()));
_timer.setSingleShot(true);
_timer.setInterval(1000);
_timer.start();
}
void ExecutaHora::mostraHora(){/*QProcess myProcess; myProcess.execute("date");*/ ConsultaBD consultaBD; consultaBD.atualizaBd();
}
and then the code has modificate to:
void AgendamentoModel::updateAgendamento(){
QDateTime today = QDateTime::currentDateTimeUtc(); QDateTime tomorrow = QDateTime::currentDateTimeUtc().addDays(1); QString sql = "UPDATE agendamento SET data = ? WHERE data < ? AND regra >= 5"; QSqlQuery query = prepareQuery(sql); query.addBindValue(tomorrow); query.addBindValue(today.currentDateTimeUtc()); qDebug() << "tomorrow = " << tomorrow; qDebug() << "today = " << today; if(query.exec()){ qDebug() << "#EXECUTOU QUERY AGENDAMENTO- UPDATEAGENDAMENTO#"; }else qDebug() << "#NAO EXECUTOU QUERY AGENDAMENTO- UPDATEAGENDAMENTO#";
}--@
thanks for the advice ! and sorry about the first comment without source code rules...
-
[quote author="nicconicco" date="1378140862"]Hi, i'm new in qt and i need some answers for my question...[/quote]
Please follow the rules of the forum and wrap the source code with @ and write the name of the framework as Qt (pronounced as cute) not QT. More information and examples about "QDateTime":http://qt-project.org/doc/qt-5.0/qtcore/qdatetime.html are available at the official online documentation.