Consider a Qdate
from
QDate Mydate = ui->dateEdit->date();
For example, suppose we choose 2018/07/14
(today).
How to obtain the day of the first Friday (in this case, 6) on the chosen month (in this case, July)?
I suspect we have to use Mydate.dayOfWeek()
computations.
There is probably a neater solution, but:
Code:
dayOfWeekToday = MyDate.dayOfWeek()
firstFriday = MyDate.day() - dayOfWeekToday + 5
firstFriday = (firstFriday <= 0) ? firstFriday + 7 : firstFriday % 7
添加到尼克的答案,需要有一个特殊情况,其中MyDate.day() - dayOfWeekToday + 5
的结果可以被 7 整除。
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.