![]() |
![]() |
![]() |
Get the current time
#include <sys/timeb.h> int ftime( struct timeb * timeptr );
libc
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
Safety: | |
---|---|
Cancellation point | No |
Interrupt handler | No |
Signal handler | Yes |
Thread | Yes |
asctime(), clock(), ctime(), difftime(), gmtime(), localtime(), mktime(), strftime(), time(), tzset()
![]() |
![]() |
![]() |