制作自定义日历时,如何设置日期并获得该月的总天数?甚至获得该特定日期的工作日?
像四月是30天,五月是31天,二月每四年是29天,而工作日则每年不同。
我正在使用Jambi(Java中的Qt 4.7),并且我希望使用很少的QComboBox
日历,并且使用QDate
来获取当前日期,如下所示:
//return current year
QDate.currentDate().year();
//return total days in current month
QDate.currentDate().daysInMonth();
//return current month
QDate.currentDate().month();
//return current day in month
QDate.currentDate().day();
//return current day in week
QDate.currentDate().dayOfWeek();
问题是我得到的是最新信息。
我如何问像2020年(2月)在那里有多少天?
2020年2月10日是星期几?
我调查了QData documentation,找不到任何设置日期的选项,所以我可以从中获取信息,有什么想法吗?
最佳答案
只需使用constructor传递您想要的日期?
例如:
QDate date = new QDate(202, 2, 1);
date.daysInMonth();