Day Number
Rupert Wood
me@rupey.net
Mon Jul 29 06:52:00 GMT 2002
dbisnath wrote:
> How does one get the day number e.g. Sunday = 0, Monday = 1 etc ?
1. Use the time() function to get the system time value
2. Use localtime() or gmtime() to parse the time value into a tm struct
3. Read the tm_wday member from the structure.
e.g.
#include <stdio.h>
#include <time.h>
int main(void)
{
time_t t;
struct tm* tmLocal;
time(&t);
tmLocal = localtime(&t);
if (tmLocal != NULL)
{
printf("It's day number %d (0=Sunday, etc.)\n",
tmLocal->tm_wday);
}
else
{
printf("Error computing day number.\n");
return 1;
}
return 0;
}
You can get further information on these functions from the manual
pages, i.e. type 'man localtime'.
Rup.
More information about the Gcc-help
mailing list