[RndTbl] Convert time in seconds to date in bash?

John Lange john.lange at open-it.ca
Tue Dec 7 14:08:51 CST 2004


I was so compelled by this question that I emailed the maintainer of
date who replied:

On Tue, 2004-12-07 at 12:01, Jim Meyering wrote: 
> If you use the coreutils from CVS, this new notation works:
> 
>   date --date=@1102439250

So there you go, there is no way to enter seconds from epoc directly
into the date command... BUT there will be some time in the future when
the CVS version is released and becomes part of most distributions.

-- 
John Lange
OpenIT ltd.
(204) 885 0872

On Tue, 2004-12-07 at 12:12, Gilbert E. Detillieux wrote:
> According to John Lange:
> > Here is how you print epoc:
> > 
> > $ date -u --date "Jan 1, 1970 00:00:00" +%s
> > 0
> > 
> > Now in our time zone:
> > $ date -u --date "Jan 1, 1970 00:00:00 +0600" +%s
> > -21600
> > 
> > So, 
> > 
> > $ date -u --date "Jan 1, 1970 00:00:00 +0600 + 1102439250 seconds"
> > Tue Dec  7 11:07:30 UTC 2004
> > 
> > Ya, that seems crazy complicated but its the only way I could get it to
> > work using strictly the bash command line.
> > 
> > Using further formating options would clean up the output including
> > correcting the timezone indicator.
> 
> Simplifying for local time zone...
> 
> % date ; date --date "Jan 1, 1970 00:00:00 +0000 + `date +%s` seconds"
> Tue Dec  7 12:09:35 CST 2004
> Tue Dec  7 12:09:35 CST 2004
> %
> 
> I wish the GNU date(1) man page would explain the input formats better.
> The simply use the keyword "STRING" without ever defining what a valid
> "STRING" would be.  There's a lot of power there, once you know what's
> allowed.





More information about the Roundtable mailing list