[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: Is there a POSIX compliant way of turning a "HH:MM:SS" formatted string to seconds? ...



On Fri, Jul 18, 2025 at 13:16:17 -0700, Michael Paoli wrote:
> E.g.:
> printf 01:02:03 | (IFS=: read h m s; printf '%s\n' $(( $((h * 3600)) +
> $((m * 60)) + $s )))

You still need to strip leading zeroes.

hobbit:~$ echo 01:08:09 | (IFS=: read h m s; printf '%s\n' $(( $((h * 3600)) +
> $((m * 60)) + $s )))
bash: 08: value too great for base (error token is "08")


Reply to: