hymie
hymie

Reputation: 2068

Converting from day-of-year to month-day in C

This is probably a FAQ, but I couldn't find anything.

My company tracks the date and time in Julian and Zulu; for example, 2014-224-17:20:00Z

I would like to write a little converter to print the date and time in EST/EDT.

Unfortunately, the mktime() function will not do this automatically. According to the man page,

The [mktime] function  ignores
the  values  supplied  by the caller in the tm_wday and tm_yday fields.

So I can apparently convert 11-aug-2014 into Julian day 223, but I cannot easily go from day 223 to a date.

Can somebody point me the way to figure out, given year 2014 and day-of-year 223, what the date is? Or is "manually" my only option?

Upvotes: 0

Views: 942

Answers (1)

Ingo Leonhardt
Ingo Leonhardt

Reputation: 9904

If you have date and time as strings, you can use strptime():

 char s[] = "2014-224-17:20:00";
 struct tm tm;

 strptime( s, "%Y-%j-%H:%M:%S", &tm );

Upvotes: 2

Related Questions