struct timeval

  • Follow


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:













7/29/2012 6:15:20 AM


Reply: