francescomoi@europe.com writes:[color=blue]
> I'm trying to show current Unix time in C.
>
> Is it possible?[/color]
If by "Unix time", you mean a raw time_t value, there's not a whole
lot you can do with it portably. The standard only guarantees that
it's an arithmetic type capable of representing times.
The following might do something useful:
#include <stdio.h>
#include <time.h>
int main()
{
printf("%ld\n", (long)time(NULL));
return 0;
}
If time_t is a floating-point type whose value is always between 0.0
and 1.0, you won't get much useful information from this. If it's,
say, an integer type representing the whole number of seconds since
1970-01-01 00:00:00 GMT, the result might be meaningful (as I write
this, it's 1112465716). <OT>The latter happens to be the
representation of time_t on Unix and some other systems, but of course
such implementation details are off-topic here.</OT>
If you want to display a legible and portable representation of the
current time, you can use something like this:
#include <stdio.h>
#include <time.h>
int main()
{
time_t now;
time(&now);
fputs(ctime(&now), stdout);
return 0;
}
--
Keith Thompson (The_Other_Keith)
kst-u@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.