Skip to contentSkip to conversation

time conversion

DISCUSSION Suma Choudhary 1 participant 1 message Aug 24, 2005

lore
Share & tools
lore
#0 lore raw

Hi
How about using time() and ctime() functions.

regards
suma

Quoted 1 line
Quoted 1 line
Quoted 1 line

"Nanakos Chrysostomos" <[email protected]> 08/23/05 13:09 PM >>>

#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;

        gettimeofday (&tv, NULL);
        ptm = localtime (&tv.tv_sec);
        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);
}

main()

{
        print_time();
}

I hope this helps.

-
To unsubscribe from this list: send the line "unsubscribe linux-c-programming" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html