[RndTbl] Convert time in seconds to date in bash?
Gilbert E. Detillieux
gedetil at cs.umanitoba.ca
Tue Dec 7 12:12:21 CST 2004
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.
--
Gilbert E. Detillieux E-mail: <gedetil at cs.umanitoba.ca>
Dept. of Computer Science Web: http://www.cs.umanitoba.ca/~gedetil/
University of Manitoba Phone: (204)474-8161
Winnipeg, MB, CANADA R3T 2N2 Fax: (204)474-7609
More information about the Roundtable
mailing list