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: Alex fxmbsw7 Ratchev
Subject: Re: EPOCHREALTIME to days, hours, minutes, seconds
Date: Fri, 20 Aug 2021 14:43:25 +0200

well i did it in my example cut the subseconds out for later addment again
..

On Fri, Aug 20, 2021, 14:37 hancooper <hancooper@protonmail.com> wrote:

> ‐‐‐‐‐‐‐ Original Message ‐‐‐‐‐‐‐
> On Friday, August 20, 2021 12:29 PM, Alex fxmbsw7 Ratchev <
> fxmbsw7@gmail.com> wrote:
>
> and if u re looking to benchmark, you cannot use the seconds var cause one
> second plus minus is no good benchmark
> at least for fast exact stuff
>
> On Fri, Aug 20, 2021, 14:27 Alex fxmbsw7 Ratchev <fxmbsw7@gmail.com>
> wrote:
>
>> EPOCHSECONDS doesnt have . dot ... EPOCHREALTIME has
>>
>> On Fri, Aug 20, 2021, 14:22 hancooper <hancooper@protonmail.com> wrote:
>>
>>> ‐‐‐‐‐‐‐ Original Message ‐‐‐‐‐‐‐
>>> On Friday, August 20, 2021 7:52 AM, Andreas Kusalananda Kähäri <
>>> andreas.kahari@abc.se> wrote:
>>>
>>> > On Fri, Aug 20, 2021 at 10:04:27AM +0300, Tapani Tarvainen wrote:
>>> >
>>> > > On Thu, Aug 19, 2021 at 06:38:12PM +0000, hancooper via (
>>> help-bash@gnu.org) wrote:
>>> > >
>>> > > > Is there a neat way to convert from decimal seconds (result from
>>> > > > EPOCHREALTIME) to days, hours, minutes, seconds?
>>> > >
>>> > > If you are treating it as a date (rather than a time difference),
>>> > > you can do simply
>>> > > A=$EPOCHREALTIME
>>> > > date -d @$A +'%d %H:%M:%S'
>>> > > Adjust format to taste.
>>> > > If it's a time difference but less than a year, and you want days,
>>> > > hours, minutes and seconds in variables, you can do it like this:
>>> > > eval $(date -d @$A +'days=%j hours=%H minutes=%M seconds=%S.%N')
>>> >
>>> > Quoting would be nice.
>>> >
>>> > > days=$((days-1))
>>> > > If you want to discard extra zeroes:
>>> > > seconds=${seconds%000}
>>> > > seconds=${seconds#0}
>>> > > hours=${hours#0}
>>> > > minutes=${minutes#0}
>>> >
>>> > If you're using bash but don't have other GNU tools installed, and only
>>> > want second granularity, then use printf instead:
>>> >
>>> > 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 ?
>>>
>>> This produces error
>>>
>>> Elapsed Time bash: printf: 13.506899: invalid number
>>> bash: printf: 13.506899: invalid number
>>> bash: printf: 13.506899: invalid number
>>> bash: printf: 13.506899: invalid number
>>>
>>>
>>> now=$EPOCHSECONDS
>>> printf -v seconds '%(%S)T' "$t"
>>>
>>
> You are correct, I was referring to EPOCHREALTIME, but my rapid typing got
> EPOCHSECONDS out instead.
>
>


reply via email to

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