Results 1 to 2 of 2

Thread: QDate::fromJulianDay

  1. #1
    Join Date
    Jan 2006
    Location
    Ohio
    Posts
    332
    Thanks
    37
    Thanked 8 Times in 4 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Red face QDate::fromJulianDay

    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!

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: QDate::fromJulianDay

    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:
    Qt Code:
    1. QDate dat(year, 1, 1);
    2. dat.addDays(days-1);
    3. qDebug() << dat.month() << dat.day();
    To copy to clipboard, switch view to plain text mode 

  3. The following user says thank you to wysota for this useful post:

    ToddAtWSU (22nd August 2008)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.