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: Tapani Tarvainen
Subject: Re: EPOCHREALTIME to days, hours, minutes, seconds
Date: Fri, 20 Aug 2021 10:04:27 +0300

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')
days=$((days-1))

If you want to discard extra zeroes:

seconds=${seconds%000}
seconds=${seconds#0}
hours=${hours#0}
minutes=${minutes#0}

-- 
Tapani Tarvainen



reply via email to

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