[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: EPOCHREALTIME to days, hours, minutes, seconds
From: |
Tapani Tarvainen |
Subject: |
Re: EPOCHREALTIME to days, hours, minutes, seconds |
Date: |
Fri, 20 Aug 2021 22:58:20 +0300 |
On Fri, Aug 20, 2021 at 10:06:53PM +0300, Tapani Tarvainen
(bash@tapanitarvainen.fi) wrote:
> now=$EPOCHREALTIME
> printf -v second '%(%S)T.%s' "${now%[^[:digit:]]*}" "${now#*[^[:digit:]]}"
> printf -v minute '%(%M)T' "${now%[^[:digit:]]*}"
> printf -v hour '%(%H)T' "${now%[^[:digit:]]*}"
Instead of [^[:digit:]], [[:punct:]] should also work.
Alternatively, you could explicitly use the decimal point
of current locale:
now=$EPOCHREALTIME
DP=$(locale decimal_point)
printf -v second '%(%S)T.%s' "${now%${DP}*}" "${now#*${DP}}"
printf -v minute '%(%M)T' "${now%${DP}*}"
printf -v hour '%(%H)T' "${now%${DP}*}"
Question: If you want to stick to bash builtins only (avoid the
locale command), is there any better way to determine the decimal
point than this:
printf -v DP "%.1f" 0
DP=${DP%?}
DP=${DP#?}
--
Tapani Tarvainen
- EPOCHREALTIME to days, hours, minutes, seconds, (continued)
- EPOCHREALTIME to days, hours, minutes, seconds, hancooper, 2021/08/20
- Re: EPOCHREALTIME to days, hours, minutes, seconds, Alex fxmbsw7 Ratchev, 2021/08/20
- Re: EPOCHREALTIME to days, hours, minutes, seconds, Alex fxmbsw7 Ratchev, 2021/08/20
- EPOCHREALTIME to days, hours, minutes, seconds, hancooper, 2021/08/20
- Re: EPOCHREALTIME to days, hours, minutes, seconds, Alex fxmbsw7 Ratchev, 2021/08/20
- Re: EPOCHREALTIME to days, hours, minutes, seconds, Tapani Tarvainen, 2021/08/20
- Re: EPOCHREALTIME to days, hours, minutes, seconds, Andreas Kusalananda Kähäri, 2021/08/20
- Re: EPOCHREALTIME to days, hours, minutes, seconds, Emanuele Torre, 2021/08/20
- Re: EPOCHREALTIME to days, hours, minutes, seconds, Alex fxmbsw7 Ratchev, 2021/08/20
- Re: EPOCHREALTIME to days, hours, minutes, seconds, Tapani Tarvainen, 2021/08/20
- Re: EPOCHREALTIME to days, hours, minutes, seconds,
Tapani Tarvainen <=
- Re: EPOCHREALTIME to days, hours, minutes, seconds, Lawrence Velázquez, 2021/08/20
- Re: EPOCHREALTIME to days, hours, minutes, seconds, Greg Wooledge, 2021/08/20
- Re: EPOCHREALTIME to days, hours, minutes, seconds, Tapani Tarvainen, 2021/08/21
- Re: EPOCHREALTIME to days, hours, minutes, seconds, Emanuele Torre, 2021/08/20
- Re: EPOCHREALTIME to days, hours, minutes, seconds, Emanuele Torre, 2021/08/20
- Re: EPOCHREALTIME to days, hours, minutes, seconds, Lawrence Velázquez, 2021/08/20
- Re: EPOCHREALTIME to days, hours, minutes, seconds, Emanuele Torre, 2021/08/20