in reply to localtime hour count
localtime accepts an epoch number representing a date and then calculates that date, converts it to the local time zone, and provides the separate fields (something like the Jan 1, 1970, 1:00:05, that is 5 seconds after the epoch, converted to your timezone). Even if you use gmtime this would still not make sense, because you are talking about a duration, and not a date.
Use DateTime to subtract the two dates, play with duration sanely, and all that, or use simple modular arithmetics:
but note that this conversion is lossy.my ( $h, $m, $s ) = do { use integer; ( ($tdelta / (60 * 60)) % 24, ($ +tdelta / 60) % 60, $tdelta % 60 ) };
You can also use Time::Duration::Object, which is convenient for formatting durations for users as '2 hours, 5 minutes' or '2 minutes, 10 seconds', that is - rounded to a certain number of units.
|
|---|