QDateTimeEdit的使用
QDateTimeEdit及QDateTime的使用
QString strYear = ui->dateTimeEdit->sectionText(QDateTimeEdit::YearSection); QString strMonth = ui->dateTimeEdit->sectionText(QDateTimeEdit::MonthSection); QString strDay = ui->dateTimeEdit->sectionText(QDateTimeEdit::DaySection); QString strHour = ui->dateTimeEdit->sectionText(QDateTimeEdit::HourSection); QString strMinute = ui->dateTimeEdit->sectionText(QDateTimeEdit::MinuteSection); QString strSecond = ui->dateTimeEdit->sectionText(QDateTimeEdit::SecondSection); QString strTime = ui->dateTimeEdit->dateTime().toString("yyyy-MM-dd HH:mm:ss"); m_dtStart = QDateTime::fromString("2021-09-17 00:11:00", "yyyy-MM-dd HH:mm:ss"); m_dtStart = ui->dateTimeEdit->dateTime(); //时间增加秒 QString MainWindow::GetTimeStr(int addSecs) { QDateTime dtFinal = m_dtStart.addSecs(addSecs); QString ret = dtFinal.toString("yyyy-MM-dd HH:mm:ss"); return ret; }