Solved Using date to covert timestamp to readable.

How do I use date to convert a timestamp (seconds since 1970) to human readable?

So for TIMESTAMP=1760757792, for example:

I can do it with date -v-$((`date +%s` - ${TIMESTAMP}))S but this uses date twice and is not so elegant.

Apparently, in linux, it can be done with date -d @${TIMESTAMP}.
 
Example:
Code:
% date -j -f %s 1759314541               
2025年 10月 1日 水曜日 19時29分01秒 JST
% date -j -Iseconds -f %s 1759314541
2025-10-01T19:29:01+09:00
% date -j -f %s 1759314541 "+%Y-%m-%d-%H:%M:%S"
2025-10-01-19:29:01
%
 
date -r 1760757792
date -r 1760757792 +"%Y-%m-%d-%H:%M:%S"
In manpage of date(1):
Code:
     -r seconds
             Print the date and time represented by seconds, where seconds is
             the number of seconds since the Epoch (00:00:00 UTC, January 1,
             1970; see time(3)), and can be specified in decimal, octal, or
             hex.
and
Code:
     -j      Do not try to set the date.  This allows you to use the -f flag
             in addition to the + option to convert one date format to
             another.  Note that any date or time components unspecified by
             the -f format string take their values from the current time.

Doesn't -r alone set system time?
 
Back
Top