I have been trying to get the day of the year into an int(0-365). I have tried the time.h library and did int tm_yday but it returned an incorrect number.
I am using Linux. G++(gcc) compiler. Thanks for the help.
I have been trying to get the day of the year into an int(0-365). I have tried the time.h library and did int tm_yday but it returned an incorrect number.
I am using Linux. G++(gcc) compiler. Thanks for the help.
Works for me:
#include <stdio.h>
#include <time.h>
int main(void)
{
time_t t = time(NULL);
struct tm *now = localtime(&t);
printf("Day of the year: %d\n", now->tm_yday);
return 0;
}
Output (for Feb 15th, 2010, EST):
Day of the year: 45
What was your "incorrect number"?
Works for me:
#include <stdio.h> #include <time.h> int main(void) { time_t t = time(NULL); struct tm *now = localtime(&t); printf("Day of the year: %d\n", now->tm_yday); return 0; }
Output (for Feb 15th, 2010, EST):
Day of the year: 45
What was your "incorrect number"?
Thanks, I see what I did wrong now.
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.