QT5 controls-QDateTimeEdit and QDateTime class, qt5-qdatetimeedit
#ifndef MAINWINDOW_H#define MAINWINDOW_H#include <QMainWindow>#include <QDateTime>#include <QDateTimeEdit>class MainWindow : public QMainWindow{ Q_OBJECTpublic: MainWindow(QWidget *parent = 0); ~MainWindow(); QDateTimeEdit* dt[10] ;};#endif // MAINWINDOW_H
# Include "mainwindow. h "MainWindow: MainWindow (QWidget * parent): QMainWindow (parent) {this-> resize (400,300 ); // display the date and time in the specified format dt [0] = new QDateTimeEdit (QDateTime: currentDateTime (), this ); dt [0]-> setDisplayFormat ("yyyy-MM-dd hh: mm: ss: zzz"); dt [0]-> setGeometry ); // specify the time fine-tuning range. Only 2 dt [1] = new QDateTimeEdit (QDateTime: currentDateTime (), this) can be transferred on year, month, and day ); dt [1]-> setMaximumDateTime (QDateTime: curren TDateTime (). addYears (2); dt [1]-> setMinimumDateTime (QDateTime: currentDateTime (). addYears (-2); dt [1]-> setDisplayFormat ("yyyy"); dt [1]-> setGeometry ); dt [2] = new QDateTimeEdit (QDateTime: currentDateTime (), this); dt [2]-> setMaximumDateTime (QDateTime: currentDateTime (). addMonths (2); dt [2]-> setMinimumDateTime (QDateTime: currentDateTime (). addMonths (-2); dt [2]-> setDisplayFormat ("MM"); dt [2]-> setGeometry (110,90, 100,50); dt [3] = new QDateTimeEdit (QDateTime: currentDateTime (), this); dt [3]-> setMaximumDateTime (QDateTime :: currentDateTime (). addDays (2); dt [3]-> setMinimumDateTime (QDateTime: currentDateTime (). addDays (-2); dt [3]-> setDisplayFormat ("dd"); dt [3]-> setGeometry (210,90, 100,50);} MainWindow ::~ MainWindow (){}
#include "mainwindow.h"#include <QApplication>int main(int argc, char *argv[]){ QApplication a(argc, argv); MainWindow w; w.show(); return a.exec();}