help-bash
[Top][All Lists]
Advanced

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

Re: EPOCHREALTIME to days, hours, minutes, seconds


From: Andreas Kusalananda Kähäri
Subject: Re: EPOCHREALTIME to days, hours, minutes, seconds
Date: Fri, 20 Aug 2021 15:50:46 +0200

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

.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]