How can I turn a timeval structure into a human readable time?
|
|
0
|
|
|
|
Reply
|
chris
|
7/2/2004 6:29:13 PM |
|
On Fri, 2 Jul 2004, chris wrote:
> How can I turn a timeval structure into a human readable time?
man strftime
--
Rich Teer, SCNA, SCSA
President,
Rite Online Inc.
Voice: +1 (250) 979-1638
URL: http://www.rite-online.net
|
|
0
|
|
|
|
Reply
|
Rich
|
7/2/2004 6:35:12 PM
|
|
Rich Teer wrote:
> On Fri, 2 Jul 2004, chris wrote:
>
>
>>How can I turn a timeval structure into a human readable time?
>
>
> man strftime
Chris also needs "man localtime" and/or "man gmtime", plus
the insight that the `tv_sec' element has the same encoding as
a `time_t'.
struct timeval tv = ...;
time_t when = tv.tv_sec;
struct tm *tm = localtime(&when);
.... and *now* he's ready for strftime().
--
Eric.Sosman@sun.com
|
|
0
|
|
|
|
Reply
|
Eric
|
7/2/2004 6:49:51 PM
|
|
Rich Teer wrote:
> On Fri, 2 Jul 2004, chris wrote:
>
>
>>How can I turn a timeval structure into a human readable time?
>
>
> man strftime
>
That says it says a tm structure, I need to use timeval
|
|
0
|
|
|
|
Reply
|
chris
|
7/2/2004 6:57:40 PM
|
|
chris <chris@misery.net> writes:
> Rich Teer wrote:
>
>> On Fri, 2 Jul 2004, chris wrote:
>>
>>>How can I turn a timeval structure into a human readable time?
>> man strftime
>>
>
> That says it says a tm structure, I need to use timeval
If the timeval struct you have was filled in by gettimeofday(), the
seconds member is an epoch time. You can turn that into a struct tm
with localtime(), and use the struct tm with strftime().
Joe
--
We can't all be heroes because someone has to sit on the curb and
clap as they go by.
- Will Rogers
|
|
0
|
|
|
|
Reply
|
joe
|
7/2/2004 7:17:18 PM
|
|
On Fri, 2 Jul 2004, Eric Sosman wrote:
> Chris also needs "man localtime" and/or "man gmtime", plus
> the insight that the `tv_sec' element has the same encoding as
> a `time_t'.
>
> struct timeval tv = ...;
> time_t when = tv.tv_sec;
> struct tm *tm = localtime(&when);
>
> ... and *now* he's ready for strftime().
Yes, of course you're right. Most of my brain was elsewhere... :-)
--
Rich Teer, SCNA, SCSA
President,
Rite Online Inc.
Voice: +1 (250) 979-1638
URL: http://www.rite-online.net
|
|
0
|
|
|
|
Reply
|
Rich
|
7/2/2004 7:46:45 PM
|
|
Eric Sosman wrote:
> Rich Teer wrote:
>
>> On Fri, 2 Jul 2004, chris wrote:
>>
>>
>>> How can I turn a timeval structure into a human readable time?
>>
>>
>>
>> man strftime
>
>
> Chris also needs "man localtime" and/or "man gmtime", plus
> the insight that the `tv_sec' element has the same encoding as
> a `time_t'.
>
> struct timeval tv = ...;
> time_t when = tv.tv_sec;
> struct tm *tm = localtime(&when);
>
> ... and *now* he's ready for strftime().
>
Thanks, working now :)
|
|
0
|
|
|
|
Reply
|
chris
|
7/2/2004 10:37:24 PM
|
|
Eric Sosman wrote:
> Rich Teer wrote:
>
>> On Fri, 2 Jul 2004, chris wrote:
>>
>>
>>> How can I turn a timeval structure into a human readable time?
>>
>>
>>
>> man strftime
>
>
> Chris also needs "man localtime" and/or "man gmtime", plus
> the insight that the `tv_sec' element has the same encoding as
> a `time_t'.
>
> struct timeval tv = ...;
> time_t when = tv.tv_sec;
> struct tm *tm = localtime(&when);
>
> ... and *now* he's ready for strftime().
>
Thanks, worked :)
|
|
0
|
|
|
|
Reply
|
chris
|
7/3/2004 4:01:44 AM
|
|
|
7 Replies
567 Views
(page loaded in 0.096 seconds)
Similiar Articles: Problem with gettimeofday() function - comp.unix.programmer ...struct timeval start_time; //Time at which timing started struct timeval end_time; //Time at which timing ended struct timeval total_time; //Total time elapsed. Problem with getch and nodelay, backspace key - comp.unix ...... error = tcsetattr(0, TCSANOW, &Ntty))) { tv.tv_sec = 0; tv.tv_usec = 100; select(1, NULL, NULL, NULL, &tv); /* a small time delay */ struct timeval ... Windows server, Unix client, connection refused on client connect ...... againg int my_connect(int sockremote, long sock_addr, short port, int timeout) { int res; struct sockaddr_in addr; long arg; fd_set myset; struct timeval tv ... How do get a timer in a thread? - comp.unix.programmervoid time_updater_start() { pthread_create( &thread, NULL, update_time_counts, NULL ); } void* update_time_counts() { struct timeval tv; unsigned int old ... open failed: illegal insecure pathname - comp.unix.solaris ...... static FUN_PROTO(type,(*name), parms) #define CAST(type, parms) (FUN_PROTO(type,(*), parms)) DECLARE(int,next_select,(int, fd_set *, fd_set *, fd_set *, struct timeval ... comp.lang.c++.moderated - page 12memory deallocation 10 62 (7/25/2003 11:07:41 AM) Hi there, I've written a function that 'converts' a structure of type timeval to a c-string: char *tv2Str(struct ... FIFO file objects - comp.unix.programmerfd_set rfds; int retval; char *buf; size_t n = 0; struct timeval tv; FILE *output = fopen("out", "a"); FILE *log = fopen("fifo", "r"); FD_ZERO(&rfds); FD_SET(fileno(log ... fgets / read / select - comp.unix.programmer... like this: char* my_fgets(char buf[], int len, FILE* fp) { .... fd_set selectset; int has_input = 0; int fn = fileno(fp); while (!has_input) { struct timeval ... Sockets in gfortran? - comp.lang.fortran... 4344 #define D_HOST "localhost" #define D_QUEUE 32 #define D_SOCKETS 16 #define D_INFO 256 int main(int argc, char **argv) { struct timeval ... Lcc and Windows 7 - comp.compilers.lccAnother small problem: compiling my code with lcc64 returns error: the compiler doesn't recognise the struct timeval (as defined in time.h), but gcc and icl compiled it. timeval structure - Microsoft Corporation: Software, Smartphones ...The timeval structure is used to specify a time interval. It is associated with the Berkeley Software Distribution (BSD) Time.h header file. struct timeval - lists.freebsd.org Mailing ListsI think we can do this with old-binary-on-new-kernel compatability, by putting in explicit padding that can be zeroed by the kernel. new-binary-on-old-kernel should ... 7/29/2012 6:15:20 AM
|