CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 6 of 6
  1. #1
    Join Date
    Apr 1999
    Posts
    32

    Julian Day Functions

    I've had a quick look using altavista, but can't find what I'm looking for. Does anyone have a pair of functions (C/C++) that will convert a Western calendar date to a Julian day number and vice versa?

    --
    Daren Chandisingh

  2. #2
    Join Date
    May 1999
    Location
    Wisconsin, USA
    Posts
    953

    Re: Julian Day Functions

    Here are two functions you may find handy.
    I could not locate any functions for Julian dates either.

    int WFSGetTimeStruct(struct tm *tmpTm, CString dateString)
    {
    int returnVal=TRUE;
    time_t now, result;
    char tmpStr[10];
    char dateStr[9];

    lstrcpy(dateStr, dateString);

    time( &now );
    *tmpTm = *localtime( &now );

    memset(tmpStr, 0x00, sizeof(tmpStr));
    strncpy(tmpStr, &dateStr[4], 2);
    tmpTm->tm_mon = atoi(tmpStr);
    tmpTm->tm_mon--;
    strncpy(tmpStr, &dateStr[6], 2);
    tmpTm->tm_mday = atoi(tmpStr);
    strncpy(tmpStr, dateStr, 4);
    tmpTm->tm_year = atoi(tmpStr);
    tmpTm->tm_year -= 1900; // value is years since 1900
    // leave time at system time setting in case user needs
    // tmpTm->tm_sec = 0;
    // tmpTm->tm_min = 0;
    // tmpTm->tm_hour = 1;
    tmpTm->tm_wday = 0;
    tmpTm->tm_yday = 0;

    result = mktime(tmpTm);

    if (result == (time_t)-1)
    {
    returnVal = FALSE;
    }

    return(returnVal);
    }


    int WFSGetJulianDate(CString dateStr)
    {
    int julianDate;
    struct tm timeStruct;

    if (WFSGetTimeStruct(&timeStruct, dateStr) == TRUE)
    {
    julianDate = timeStruct.tm_yday + 1;
    }
    else
    {
    julianDate = -1;
    }

    return(julianDate);
    }



  3. #3
    Join Date
    May 1999
    Location
    Oregon, USA
    Posts
    302

    Re: Julian Day Functions

    I think PJ Naughter has some code for this.
    His page is at http://indigo.ie/~pjn/



  4. #4
    Guest

    Re: Julian Day Functions


  5. #5
    Join Date
    May 1999
    Location
    Houston - TX - US
    Posts
    29

    Re: Julian Day Functions

    Hi,

    struct tm *today;
    time_t ltime;
    char buff[10];

    time ( &ltime);
    today = localtime (&ltime);
    strftime (buff, 7, " %y%j", today);
    // see help on strftime for more info on
    //different date formats!

    hope this helps You.

    Good Luck.
    Yash.


  6. #6
    Guest

    Re: Julian Day Functions

    Send me your e-mail address and I'll forward you a couple of excellent routines (straight C and throughly documented).

    Jeff Raft
    E-Mail: [email protected]


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured