Click to See Complete Forum and Search --> : Julian Day Functions
Daren Chandisingh
April 7th, 1999, 05:07 AM
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
PeterK
April 7th, 1999, 11:56 AM
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);
}
Gomez Addams
April 7th, 1999, 01:49 PM
I think PJ Naughter has some code for this.
His page is at http://indigo.ie/~pjn/
April 8th, 1999, 03:54 AM
or try www.snippets.org
yash
April 8th, 1999, 09:39 AM
Hi,
struct tm *today;
time_t ltime;
char buff[10];
time ( <ime);
today = localtime (<ime);
strftime (buff, 7, " %y%j", today);
// see help on strftime for more info on
//different date formats!
hope this helps You.
Good Luck.
Yash.
April 9th, 1999, 10:46 PM
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: jraft@home.com
codeguru.com
Copyright Internet.com Inc., All Rights Reserved.