Simple C question
Bruce Marshall
bmarsh
Fri Jan 14 10:06:29 PST 2005
On Friday 14 January 2005 09:03 am, Kurt Wall wrote:
> On Fri, Jan 14, 2005 at 08:19:47AM -0500, Bruce Marshall took 24 lines to
write:
> > I have a program written in C that I wrote long, long ago in the other
> > operating system.
> >
> > The only thing it needs to bring it over to Linux is a call to get the
> > current date and time.
>
> Several approaches. I usually use time() to get the calendar time
> and then ctime() to format it a a proper string:
>
> #include <stdio.h>
> #include <time.h>
>
> int main()
> {
> time_t now;
>
> time(&now);
> printf("%s", ctime(&now));
> return 0;
> }
>
> You can also do something like asctime(localtime(&now));. Note that ctime()
> appends the terminating newline ('\n'), so you don't need to include it
> in your format string.
>
> Kurt
Hmmm probably could have dug that out of a book I have here written by
someone named Wall.... :-)
Thanks....!
--
+----------------------------------------------------------------------------+
+ Bruce S. Marshall bmarsh at bmarsh.com Bellaire, MI 01/14/05 10:01 +
+----------------------------------------------------------------------------+
"Proverbs are mental gems gathered in the diamond districts of the mind."
- W. R. Alger
More information about the Linux-users
mailing list