www.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1999/08/02/21:04:39

Date: Mon, 2 Aug 1999 13:29:27 +0300 (IDT)
From: Eli Zaretskii <eliz AT is DOT elta DOT co DOT il>
X-Sender: eliz AT is
To: Rich <calculs2 AT erie DOT net>
cc: djgpp AT delorie DOT com
Subject: Re: Printing the PROPER current Date/Time
In-Reply-To: <1.5.4.16.19990801222107.337fe474@erie.net>
Message-ID: <Pine.SUN.3.91.990802132904.4488Q-100000@is>
MIME-Version: 1.0
Reply-To: djgpp AT delorie DOT com
X-Mailing-List: djgpp AT delorie DOT com
X-Unsubscribes-To: listserv AT delorie DOT com

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 -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019