www.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1998/09/29/21:53:47

Message-ID: <36118D7D.9BC37287@montana.com>
Date: Tue, 29 Sep 1998 19:46:37 -0600
From: bowman <bowman AT montana DOT com>
Reply-To: bowman AT montana DOT com
X-Mailer: Mozilla 4.5b2 [en] (Win95; I)
X-Accept-Language: en
MIME-Version: 1.0
To: tonyblaha AT juno DOT com, "djgpp AT delorie DOT com" <djgpp AT backup DOT delorie DOT com>
Subject: Re: newbie: strftime
References: <19980929 DOT 140919 DOT 9735 DOT 0 DOT tonyblaha AT juno DOT com>


tonyblaha AT juno DOT com wrote:
> 
> I'm having trouble with the strftime() function in time.h.
> I've copied the example directly from libc.inf:
> But I can't get it to work.

The example is a little confusing, in that is doesn't mention that t
needs to be filled out.

time_t current_time;
struct tm* t;
char buf[100];


current_time = time(NULL);		// get the current system time
t = localtime(&current_time);		// adjust for local parameters
strftime(buf, 100, "%B %d, %Y", &t);	// format it to your taste
puts(buf);				// and print it


note that 'localtime' or 'gmtime' return a pointer to a static buffer
that they maintain.

- Raw text -


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