Mail Archives: djgpp/1999/08/02/21:04:39
On Sun, 1 Aug 1999, Rich wrote:
> time_t secs_now;
>
> //Copied from LIBC.HLP file.
> /* time_t mktime(struct tm *tptr); */
> /* time_t time(time_t *t); */
> /* struct tm *localtime(const time_t *tod); */
>
> int main(int argc, char **argv) {
> char buf[100];
>
> time_now = localtime(&secs_now);
>
> strftime(buf, 100, "%B %d, %Y", time_now);
>
> printf("%s\n", buf);
>
> }
> ------------------
> Outputs:
> January 01, 1970
> ------------------
> How do I get a PROPER Date/Time (like from the system clock)?
You are passing to `localtime' a value of zero, which corresponds to
the so-called ``epoch'', January 1, 1970. You need to set the
argument of `localtime' to the current time, like this:
time_t secs_now = time (NULL);
struct tm *time_now = localtime (&secs_now);
Then call `strftime' or whatever.
- Raw text -