Locally invoke date +%Z
, date +%:z
(see man 1 date
) or another command to learn the timezone you're in. Or maybe you already know it's e.g. Asia/Hong_Kong
. Then on the server set TZ
accordingly when you invoke last
. Example:
# on server
TZ=Asia/Hong_Kong last
The server must know the timezone. Alternatively:
# on server
TZ=foo-8 last
# or even
TZ=bar-08:45 last
(foo
and bar
are arbitrary 3-letter strings here).
Note there is a quirk: if (local) date +%:z
tells you +08:00
then you need to set TZ=foo-08:00
or TZ=foo-8
. If it tells you -08:00
then TZ=foo+08:00
.
You can set TZ
and export
it in the remote shell, so it affects your entire session.
If I read man 1 ssh
right, the server will put TZ
in your environment if the variable is in the environment of the daemon (sshd
). To use your local TZ
automatically the server needs to be configured. (And before you test various ideas note your local TZ
may or may not be set in the first place).
A somewhat cumbersome way to pass your local timezone to the remote side is to embed variable assignment in the command itself. Example:
# locally
ssh user@server "TZ='foo$(date +%:z | tr +- -+)' last"
date +%:z | tr +- -+
is executed locally (tr
because of the quirk).
TZ=Asia/Hong_Kong last
works, butTZ=foo-8 last
didn't work. – water77 Feb 21 '20 at 21:45