Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

command line > date +%j

Status
Not open for further replies.

cassie99

Programmer
Dec 20, 2001
26
US
Hello.

My dilemma:
I would like to create a function that returns the UNIX system date with a julian day format (date +%j). Since it doesn't look like I can use:

int jul;
jul=system("date +%j");
return jul;

Any ideas on what I could use to make this work? Thanks in advance.

Cassie
 
What about the following code snippet...

#include <time.h>

int get_julian()
{
static int julian;
struct tm * ttm;
time_t t;

t=time(NULL);
ttm=localtime(&t);
julian=(((ttm->tm_year+1900)%100)*1000)+(ttm->tm_yday+1);
return julian;
}


Cheers - Gavin
 
Thanks Gavin. Your post is very similar to what I ended up using.

//get julian day
int getJulianDay()
{
time_t d1;
struct tm *f;
time(&d1);

f = localtime(&d1);
int jul;
jul = (f->tm_yday)+1;
return jul;
}

Regards,
Cassie
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top