0

When making customize calendar, how can I set a date and get the total days of that month? Or even get the week day of that specific date? Like April is 30 Days, May is 31 days, February every 4 years is 29 days and week days are different every year.

I'm using Jambi (Qt 4.7 in java) and I want to make calendar with few QComboBox, and I use QDate to get the current date like so:

//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();

The thing is that what I'm getting is current information.

  1. How can I ask like in year 2020, month February, how many days are in there?
  2. And 10th, February, 2020 is which day in week?

I looked into QData documentation, I couldn't find any option to set date so i can get info from it, any ideas?

Smar
  • 8,109
  • 3
  • 36
  • 48
Bear
  • 550
  • 9
  • 25

1 Answers1

1

Just use the constructor to pass the date you want?

For example:

QDate date = new QDate(202, 2, 1);
date.daysInMonth();
Smar
  • 8,109
  • 3
  • 36
  • 48
  • thanks, Yeah that's work, also what about second question, "which day in week"? like is it Monday or ...? – Bear Apr 25 '16 at 07:41
  • oh, you meant `QDate` right? i thought you are talking about java built in `Date`, yeah if i use `QDate` it will work perfectly, also since everything is String i can just use `QDate second_date = QDate.fromString("1022020", "dMyyyy");` so i don't need to convert them to Integer. – Bear Apr 25 '16 at 08:33
  • 1
    Yes, I meant `QDate`. Fixed the answer. For getting week day number of the day, you can just look last thing in your answer ;) (spoiler: `daysOfWeek()`). `currentDate()` just constructs the object for you, you can always do it manually too. The doc should tell everything you need. – Smar Apr 25 '16 at 09:02