short version: man ctime.
longer version:
lola% more now.c
#include <stdio.h>
#include <time.h>
int main(int argc, char *argv[]) {
time_t now;
struct tm *d;
time(&now);
printf("hello world. It is now %10ld seconds since the epoch began\n",
now);
d = localtime(&now);
printf("for mere humans, today is: %d/%d/%d\n", 1900+d->tm_year,d->tm_mon,
d->
tm_mday );
}
lola%
lola% ./now
hello world. It is now 1293986153 seconds since the epoch began
for mere humans, today is: 2011/0/2
lola%
On Sun, Jan 2, 2011 at 10:18 AM, Leslie S Satenstein
<[email protected]>wrote:
> Happy New Year.
>
> I have been trying to find a simple example to retrieve the computer date
> using documented routines.
>
> I want to retrieve three integers corresponding to year, month and day.
>
> I took the time() function and subtracted the number of seconds we are
> behind GMT 0, and converted seconds to days since 1979-01-01
>
> From there I did calculate the current date. However, rather than
> supporting my own code, I would have liked to have use localtime(), and
> time(), etc, but...
>
> I get compile errors for tm->year, tm->mon and tm->mday.
>
> Searching the includes, results in no function that returns the integters
> Ditto for a google search.
>
> Any standard function to complete and return the tm structure as defined
> in time.h would be appreciated.
>
>
> ------------------
>
> Regards
> Leslie
> Mr. Leslie Satenstein
> 40 years in IT and going strong.
> Yesterday was a good day, today is a better day,
> and tomorrow will be even better.
>
> mailto:[email protected]
> alternative: [email protected]
> www.itbms.biz / www.eclipseguard.com
>
> _______________________________________________
> mlug mailing list
> [email protected]
> https://listes.koumbit.net/cgi-bin/mailman/listinfo/mlug-listserv.mlug.ca
>
_______________________________________________
mlug mailing list
[email protected]
https://listes.koumbit.net/cgi-bin/mailman/listinfo/mlug-listserv.mlug.ca