Hi,
Have a look at this program which may help you.
I tried to print the time.
Thanks & Regds,
T.Mohanta
cat time.c
#include <stdio.h>
#include <sys/time.h>
#include <time.h>
#include <unistd.h>
void print_time ()
{
struct timeval tv;
struct tm* ptm;
char time_string[40];
long milliseconds;
double sec;
double secs;
/* Obtain the time of day, and convert it to a tm struct.
*/
gettimeofday (&tv, NULL);
ptm = localtime (&tv.tv_sec);
/* Format the date and time, down to a single second. */
strftime (time_string, sizeof (time_string), "%Y-%m-%d
%H:%M:%S",
ptm);
/* Compute milliseconds from microseconds. */
milliseconds = tv.tv_usec / 1000;
sec = tv.tv_sec;
/* Print the formatted time, in seconds, followed by a
decimal
point
* and the milliseconds. */
printf ("The sec--- value %d\n", sec);
printf ("%s\n", time_string);
printf ("The sec value %d\n", ptm->tm_sec);
printf ("%s.%03ld\n", time_string, milliseconds);
printf ("The min value ======%d\n", ptm->tm_min);
//printf ("%s.%03ld\n", time_string, milliseconds);
printf ("%d\n", time_string, milliseconds);
sleep(2);
gettimeofday (&tv, NULL);
secs = tv.tv_sec;
ptm = localtime (&tv.tv_sec);
/* Format the date and time, down to a single second. */
strftime (time_string, sizeof (time_string), "%Y-%m-%d
%H:%M:%S",
ptm);
milliseconds = tv.tv_usec / 1000;
printf ("%s.%03ld\n", time_string, milliseconds);
printf ("The sec--- value %d\n", secs);
printf ("The sec value %d\n", ptm->tm_sec);
printf ("The min value %d\n", ptm->tm_min);
printf ("The diff value %d\n", (secs-sec));
}
int main ()
{
print_time();
return 0;
}