[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: EPOCHREALTIME to days, hours, minutes, seconds
From: |
Emanuele Torre |
Subject: |
Re: EPOCHREALTIME to days, hours, minutes, seconds |
Date: |
Fri, 20 Aug 2021 18:39:04 +0200 |
> now=$EPOCHREALTIME
> printf -v seconds "%(%S)T.%s" "${now%.*}" "${now#*.}"
> printf -v minutes '%(%M)T' "${now%.*}"
> printf -v hours '%(%H)T' "${now%.*}"
Also, EPOCHREALTIME may not have "." as the decimal delimiter since it
uses the one of the current locale (LC_NUMERIC). So it's more
appropriate to use [!0-9] rather than ".".
now=$EPOCHREALTIME
printf -v second '%(%S)T.%s' "${now%[!0-9]*}" "${now#*[!0-9]}"
printf -v minute '%(%M)T' "${now%[!0-9]*}"
printf -v hour '%(%H)T' "${now%[!0-9]*}"
--
emanuele6
On 20/08/2021, Andreas Kusalananda Kähäri <andreas.kahari@abc.se> wrote:
> On Fri, Aug 20, 2021 at 04:34:20PM +0300, Tapani Tarvainen wrote:
>> On Fri, Aug 20, 2021 at 12:22:21PM +0000, hancooper
>> (hancooper@protonmail.com) wrote:
>>
>> > > now=$EPOCHSECONDS
>> > > printf -v seconds '%(%S)T' "$now"
>> > > printf -v minutes '%(%M)T' "$now"
>> > > printf -v hours '%(%H)T' "$now"
>>
>> > How can I deal with seconds that includes fractional part ?
>>
>> The Gnu date -based solution I posted earlier deals with them,
>> but the above can be modified to do it as well:
>>
>> now=$EPOCHREALTIME
>> printf -v seconds "%(%S)T.${now#*.}" "${now%.*}"
>> printf -v minutes '%(%M)T' "${now%.*}"
>> printf -v hours '%(%H)T' "${now%.*}"
>>
>> --
>> Tapani Tarvainen
>
> Don't inject data into the printf format string. Instead:
>
> now=$EPOCHREALTIME
> printf -v seconds "%(%S)T.%s" "${now%.*}" "${now#*.}"
> printf -v minutes '%(%M)T' "${now%.*}"
> printf -v hours '%(%H)T' "${now%.*}"
>
> --
> Andreas (Kusalananda) Kähäri
> SciLifeLab, NBIS, ICM
> Uppsala University, Sweden
>
> .
>
>
- Re: EPOCHREALTIME to days, hours, minutes, seconds, (continued)
- 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
- 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 <=
- 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, 2021/08/20
- 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
- Prev by Date:
Re: EPOCHREALTIME to days, hours, minutes, seconds
- Next by Date:
Re: EPOCHREALTIME to days, hours, minutes, seconds
- Previous by thread:
Re: EPOCHREALTIME to days, hours, minutes, seconds
- Next by thread:
Re: EPOCHREALTIME to days, hours, minutes, seconds
- Index(es):