PDA

View Full Version : QDate::fromJulianDay



ToddAtWSU
21st August 2008, 19:15
I have a Day of Year value and a year value and need to get the Month and Day from this value. I was hoping to use the QDate object to do this, but I am having issues seeing how this is possible. I thought I could use QDate::fromJulianDay but this does not ask what year you are using therefore how do I know what year my QDate object will be in? This is important for leap years versus non-leap years because the DOY is greatly affected by this once you hit Feb 29 or later.

I thought about then setting the year in the QDate object but this will just screw up what value it thought the day and month should be when you used the fromJulianDay function. Thanks for your help with this matter. If this is not possible, I will just code up the function to do this for me. Thanks!

wysota
21st August 2008, 19:49
The easiest "hard way" is to convert what you have to a Unix timestamp (aka time_t) and then use a proper method from QDate. But you might also try this:

QDate dat(year, 1, 1);
dat.addDays(days-1);
qDebug() << dat.month() << dat.day();