| TIP: Click on subject to list as thread! | ANSI |
| echo: | |
|---|---|
| to: | |
| from: | |
| date: | |
| subject: | Day of year |
> How do you calculate the day of the year in C?
Not necessary. In the standard library header file you
should find the struct tm listed. This has a member, tm_yday that
represents the number of days since Jan 1.
Time functions can be a little tricky, so maybe an example would help:-
#include
int showday(void)
{ time_t t = time(&t);
return gmtime(&t)->tm_yday;
}
int main(void)
{ return printf("%d\n",showday()); }
I am sorry that you find SNIPPETS hard to use. Nevertheless, the code
above is ANSI standard C snd should work on all compilers and all platforms
that comply with the standard.
There is also strftime() available, but IIRC that requires the header
file .
Best wishes,
Bill.
---
* Origin: Meerkats Anonymous (2:2504/200)SEEN-BY: 396/1 632/0 371 633/260 262 267 270 371 634/397 635/506 728 639/252 SEEN-BY: 670/218 @PATH: 2504/200 213 255/3 1 251/25 396/1 633/260 635/506 728 633/267 |
|
| SOURCE: echomail via fidonet.ozzmosis.com | |
Email questions or comments to sysop@ipingthereforeiam.com
All parts of this website painstakingly hand-crafted in the U.S.A.!
IPTIA BBS/MUD/Terminal/Game Server List, © 2025 IPTIA Consulting™.