The Code Project View our sponsorsClick here for Dundas Consulting - experts in MFC, C++, TCP/IP and ASPAdvertise on the CodeProject
Home >> Date / Time handling >> General

Sunrise/Sunset Calculations
By Brian Heilman

Code to help calculate sunrise and sunset times 
 VC 4-6, Win95-98, NT4, W2K, MFC
 Posted 19 Jul 2000
 Updated 15 Dec 2000
Articles by this author
Send to a friend
Printer friendly version
Lounge New Articles Sign in Forums Contribute
Broken links? Email us!
19 users have rated this article. result:
4.79 out of 5.

  • 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....

    About Brian Heilman

    Software Engineer with several years Visual C++
    experience.
    Has worked on various commercial applications
    including:
    *GIS Mapping software(FAAR) for NMT Corporation
    *Destination Direct Flight Planning for Delta Technology(flightplan.com)

    And my own applications:
    * "DealerForms" - car Dealer software
    * "UglyBass Utilities" and "UglyBass The Game" at UglyBass.com
    * and the big ol' etc....

    And now am working on websites like www.uglybass.com, using PERL, Javascript and
    a touch of HTML too.... More coming...

    Click here to visit Brian Heilman's homepage.

    [Top] Sign in to vote for this article:     PoorExcellent  
    Hint: For improved responsiveness, use Internet Explorer 4 (or above) with Javascript enabled, choose 'Use DHTML' from the View dropdown and hit 'Set Options'.
     Keyword Filter
     View   Per page   Messages since
    New threadMessages 1 to 4 of 4 (Total: 4)First Prev Next Last
    Subject 
    Author 
    Date 
      What about height ?
    Miron Ophir 9:35 30 Dec 00 
      convert UTC to LOCAL
    Brian H 15:51 21 Nov 00 
      CTime
    Norm Almond 11:45 20 Jul 00 
      Re: CTime
    Crispy 18:22 18 Dec 00 
    Last Visit: 12:00 Friday 1st January, 1999First Prev Next Last

    Home >> Date / Time handling >> General
    last updated 15 Dec 2000
    Article content copyright Brian Heilman, 2000
    everything else © CodeProject, 1999-2001.
    The Code Project View our sponsorsGet your new domain name now!Advertise on the CodeProject