linux-c-programming.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* time conversion
@ 2005-08-23  7:30 Lejanson C. Go
  2005-08-23  7:42 ` Nanakos Chrysostomos
  2005-08-23 14:07 ` kranthi
  0 siblings, 2 replies; 4+ messages in thread
From: Lejanson C. Go @ 2005-08-23  7:30 UTC (permalink / raw)
  To: linux-c-programming

Hi,

I had searched the net on how to convert unsigned long timestamp
to human readable format or maybe in struct timeval format. Any sample 
code that you can share would be greatly appreciated.
Thanks.

Lejanson



^ permalink raw reply	[flat|nested] 4+ messages in thread
* Re: time conversion
@ 2005-08-24  2:21 Suma Choudhary
  0 siblings, 0 replies; 4+ messages in thread
From: Suma Choudhary @ 2005-08-24  2:21 UTC (permalink / raw)
  To: lejanson, nanakos; +Cc: linux-c-programming

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

regards
suma

>>> "Nanakos Chrysostomos" <nanakos@wired-net.gr> 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 majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2005-08-24  2:21 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2005-08-23  7:30 time conversion Lejanson C. Go
2005-08-23  7:42 ` Nanakos Chrysostomos
2005-08-23 14:07 ` kranthi
  -- strict thread matches above, loose matches on Subject: below --
2005-08-24  2:21 Suma Choudhary

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).