Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I make Tmux display time in a different time zone?

Tags:

datetime

tmux

Hitting <tmuxPrefix> + t displays the time on my server but I want it to display the time in my current timezone rather than the server's timezone.

I run into the same issue when I want to display the time in the status bar in my current timezone.

I was able to partially fix it by using the following command:

set -g status-right '#(TZ="Asia/Kolkata" date )'

But when I use modifiers like %H, %M, %S in the status, as below, it ends up showing the time in the server's time zone.

set -g status-left '%H:%M:%S'

I have updated my .bashrc config with TZ="Asia/Kolkata". This gives me time in the right timezone when I run the time command in bash but it doesn't seem to use the variable in a Tmux session.

Can anyone please let me know how I can fix it?

like image 700
rks Avatar asked Jul 08 '16 06:07

rks


2 Answers

For the second part of your question, you can use:

set -g status-right '#(TZ="Asia/Kolkata" date +%%H:%%M:%%S)'
like image 85
Steven Tian Avatar answered Oct 19 '22 08:10

Steven Tian


What I do is set the timezone for my user. It works beyond tmux, it will translate anything that displays dates and times, like the output of 'ls' for example.

Edit your ~/.profile and set the TZ variable, for example:

export TZ=/usr/share/zoneinfo/US/Pacific

You can also make ssh send your current timezone automatically. Make sure you have TZ in the ~/.profile of your laptop then instruct ssh to send it by adding this to ~/.ssh/config

SendEnv TZ

The remote server has to be configured to accept it, if it doesn't work make sure it has this in /etc/ssh/sshd_config

AcceptEnv LANG LC_* TZ
like image 35
GiBaTr0n Avatar answered Oct 19 '22 07:10

GiBaTr0n