Click here to Skip to main content
Licence 
First Posted 18 Jul 2000
Views 105,907
Bookmarked 26 times

Sunrise/Sunset Calculations

By | 14 Dec 2000 | Article
Code to help calculate sunrise and sunset times
  • Download source files - 4 Kb
  • Download demo project - 12 Kb
  • Introduction

    I searched the web for a piece of code that calculates the Sunrise/Sunset based on the Date and a latitude and longitude, but could not find one in C++ that was freely available. People have FreeWare out there, but were unwilling to give out the source as they deemed it to "valuable". So I took it upon myself to convert one of the other freely available pieces of code, and convert it for everyone to use.

    I have written a the following C++ code. It is based heavily on the Javascript I obtained directly from the NOAA. I find that many applications may have a use for this information, so feel free to use it to make your own FreeWare tray applications, or any other Utility Programs.

    The Main three functions are:

    CTime GetSunset(double dLat,double dLon,CTime time);
    CTime GetSunrise(double dLat,double dLon,CTime time);
    CTime GetSolarNoon(double dLon, CTime time);
    

    which take in Latitude and Longitude values as doubles and a CTime with the Date that you want to calculate the SR/SS for. It returns a CTime in UTC.

    I have included a non-MFC Tray icon class I have written, with the example.. It has the basic functionality to display a tray icon, and can be used in MFC, Win32 and ATL applications. Probably not as good as the newest CSystemTray, but I use it with Win32 to make very small footprint applications!!

    I have also added more functionality to the demo, as the way I originally submitted it, it had very little actual functionality. I also added the code so it is converted from UTC as well.

    Hope someone finds it Useful....

    License

    This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

    A list of licenses authors might use can be found here

    About the Author

    Brian Heilman

    Software Developer
    Birdsoft
    United States United States

    Member

    Software Engineer with years of Visual C++ and Objective-C
    experience.
     
    Developed Windows Mobile applications including All-In Hold 'Em, Extreme Agenda, and The Dog Ate It.
     
    Now mostly iOS development with the popular title Extreme Agenda as a flagship.

    Sign Up to vote   Poor Excellent
    Add a reason or comment to your vote: x
    Votes of 3 or less require a comment

    Comments and Discussions

     
    You must Sign In to use this message board. (secure sign-in)
     
    Search this forum  
     FAQ
        Noise  Layout  Per page   
      Refresh
    Bugyou have a bug in minus location PinmemberMember 769785822:00 10 Sep '11  
    QuestionGreat stuff is there a fix for DST? PinmemberRobert Valentino3:45 6 Apr '11  
    Generalhelp PinmemberMember 76555215:10 8 Feb '11  
    GeneralMy vote of 2 Pinmembercraig.miller13:01 26 May '10  
    GeneralRe: My vote of 2 PinmemberPat Kujawa5:46 24 Mar '11  
    QuestionCan i have C# version of this code Pinmembertoashokin23:01 15 Sep '09  
    AnswerRe: Can i have C# version of this code PinmemberPat Kujawa5:46 24 Mar '11  
    QuestionDoes anyone know how to get the Noon Rise / set times from this? Pinmemberpeterdrozd3:52 20 Aug '08  
    QuestionDid anyone do a clean up? PinmemberJustASoftwareGuy668:50 23 Dec '06  
    Generalwrong result? help Pinmemberanqincmt13:50 5 Dec '05  
    GeneralCorrect UTC Offset Pinmemberjheddings15:22 1 Dec '05  
    Questionconverting to vb.net? Pinmembermichal_s_w8:31 1 Nov '05  
    GeneralComparison didn't work PinmemberJWood16:25 3 May '05  
    GeneralNorth/South & West/East PinsussStanislav Khatsko3:27 24 Oct '04  
    GeneralInput PinmemberPiccinano3:36 25 Feb '03  
    GeneralRe: Input PinsussAnonymous14:03 21 Jun '03  
    GeneralRe: Input PinsussStanislav Khatsko3:32 24 Oct '04  
    GeneralDaylight Savings PinmemberDarroll Walsh4:42 9 Apr '02  
    GeneralRe: Daylight Savings PinmemberDarroll Walsh5:20 9 Apr '02  
    GeneralRe: Daylight Savings PinsussEzel32:24 24 Nov '03  
    GeneralRe: Daylight Savings PinsussKSharenkov18:02 11 Jan '05  
    GeneralDosen't work ;( PinmemberTutankhamen5:14 2 Jul '01  
    GeneralRe: Dosen't work ;( Pinmembercraig.miller13:02 26 May '10  
    QuestionWhat about height ? PinmemberMiron Ophir3:35 30 Dec '00  
    Generalconvert UTC to LOCAL PinmemberBrian H9:51 21 Nov '00  

    General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

    Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

    Permalink | Advertise | Privacy | Mobile
    Web02 | 2.5.120517.1 | Last Updated 15 Dec 2000
    Article Copyright 2000 by Brian Heilman
    Everything else Copyright © CodeProject, 1999-2012
    Terms of Use
    Layout: fixed | fluid