Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

current datetime in QString?

Tags:

c++

qt

qt5

so far im using:

QTime time = QTime::currentTime();
QString formattedTime = time.toString("hh:mm:ss");
QByteArray formattedTimeMsg = formattedTime.toLocal8Bit();

how do i change this to have date and time as "DD.MM.YYYY hh:mm:ss"?

like image 829
Jiri Zaloudek Avatar asked Jun 10 '26 21:06

Jiri Zaloudek


1 Answers

QDateTime date = QDateTime::currentDateTime();
QString formattedTime = date.toString("dd.MM.yyyy hh:mm:ss");
QByteArray formattedTimeMsg = formattedTime.toLocal8Bit();

qDebug() << "Date:"+formattedTime;

You can find more details here https://doc.qt.io/qt-5/qdatetime.html

like image 144
ozkanpakdil Avatar answered Jun 13 '26 12:06

ozkanpakdil