1、QCalendarWidget calendar1 = new QCalendarWidget(this);


2、获取系统时间:QDateTime now = QDateTime::currentDateTime();
再获取一个时间:QDateTime begin = new.addSecs(-2678400);//增加的是秒数

目的是起始时间和截止时间产生时间差。
3、QDateTime转换QDate
QDateTime now = QDateTime::currentDateTime();
QDate tmpdate;
tmpdate = now.date();
QDate转换QString:QString _tmpdate; _tmpdate = tmpdate.toString();
最后把字符串放入label中 textLabel = setText(_tmpdate);完成时间显示在界面中。
4、如何获取日历中你所选中的时间并且显示到当前界面中
首先connect(calendar1 ,SIGNAL(clicked(QDate)),this,SLOT(on_calendar1_clicked(QDate)));
接着完成槽函数:
void *******::on_calendar1_clicked(QDate Val)
{
date1 = calaendar1->selectedDate();
QString str;
str = date1.toString("yyyy年MM月dd日");
_textLabel->setText(str);
}
.
网友评论