Get the current time
#include <sys/timeb.h> int ftime( struct timeb * timeptr );
libc
Use the -l c option to qcc to link against this library. This library is usually included automatically.
The ftime() function stores the current time in the timeptr structure. The timeb structure contains the following fields:
#include <stdio.h> #include <time.h> #include <sys/timeb.h> #include <stdlib.h> int main( void ) { struct timeb timebuf; char *now; ftime( &timebuf ); now = ctime( &timebuf.time ); /* Note that we're cutting "now" off * after 19 characters to avoid the * \n that ctime() appends to the * formatted time string. */ printf( "The time is %.19s.%hu\n", now, timebuf.millitm ); return EXIT_SUCCESS; }
Produces output similar to the following:
The time is Mon Jul 05 15:58:42.870
Standard Unix; removed from POSIX.1-2008
Safety: | |
---|---|
Cancellation point | No |
Interrupt handler | No |
Signal handler | Yes |
Thread | Yes |