| ID | ... | Creation date | June 11, 2009 |
| Platform | S60 3rd Edition, FP1, FP2 S60 5th Edition | Tested on devices | Nokia 5800 XpressMusic |
| Category | Qt for Symbian | Subcategory |
| Keywords (APIs, classes, methods, functions): QDateTime::currentDateTime(), QDate::currentDate(), QTime::currentTime() |
This code snippets shows how to get current date and time of device. API QDateTime::currentDateTime() will returns the current date and time, as reported by the system clock, in the local time zone. The QDate::currentDate() will return the current date , as reported by the system clock, in the local time zone. The QTime::currentTime() will return the current time , as reported by the system clock, in the local time zone.
This snippet can be self-signed. As it does not use any API which require developer/certified signing.
#include <QDateTime>
SystemTime::SystemTime(QWidget *parent)
: QMainWindow(parent)
{
ui.setupUi(this);
setWindowTitle("System Time");
ui.statusbar->showMessage("Showing system time");
//get current date
QDate date = QDate::currentDate();
QString dateString = date.toString();
ui.label->setText("Date: " + dateString);
//get current time
QTime time = QTime::currentTime();
QString timeString = time.toString();
ui.label_2->setText("Time: " + timeString);
//get current date and time
QDateTime dateTime = QDateTime::currentDateTime();
QString dateTimeString = dateTime.toString();
ui.label_3->setText("Date and Time: " + dateTimeString);
}
The code snippet is expected to show current date and time of device.