How may I pipe a timestamp to date and convert it to datetime?

Assume we have a timestamp like below:

[xxxxxx ~]$ date -d@1530586185
Tue Jul  3 05:49:45 EEST 2018

and I want to pipe it to date like:

echo 1530586185 | date -d@
date: invalid date ‘@’   <-------- error message

How can I do it?

1 answer

  • answered 2018-07-12 07:05 Rene Knop

    Suggestion 1:

    date -d"@$(echo 1530586185)"
    

    Suggestion 2:

    DATE=$(echo 1530586185); date -d"@$DATE"