We help IT Professionals succeed at work.

Time Duration variable

artwilkes
artwilkes asked
on
I need a variable to hold a time duration in c++, like how long something takes to print a document.  I seem to remember that there was a variable type for duration.  But a google search did not turn up anything.  I need the variable and the process for encoding and decoding the variable. Thanks
Comment
Watch Question

ozo
Most Valuable Expert 2014
Top Expert 2015

Commented:
depending on your needs, you might use an int multiple of your smallest time interval, or a float multiple of a longer time interval that may be more meaningful to you.
If you also need to deal with calendar dates, perhaps different time zones, perhaps treating business days and holidays differently, you may need more sophisticated objects.
Top Expert 2009
Commented:
The way standard C (and C++) deal with time differences, is shown in the difftime function :

        http://www.cplusplus.com/reference/clibrary/ctime/difftime/

ie. the time difference is expressed using a double value.

However, that's as far as the standard goes with this. No further functionality to deal with time differences is included. Anything additional you need, will have to be implemented in your platform's extensions, a third party library, or by yourself.

Author

Commented:
Thanks for the review.  This is a good example.