We are developing Linux based application and we would like to set the time zone on a per user basis for individual user. How do I configure Fedora Linux or any Unix like oses to set the time zone on a per user basis using bash shell?
A time zone is a region of the Earth that has adopted the same standard time, usually referred to as the local time. Most adjacent time zones are exactly one hour apart, and by convention compute their local time as an offset from Greenwich Mean Time.
You can set the time zone system-wide using this method. However use following instructions to set the time zone on a per user basis.
Most Unix based systems, including Linux and Mac OS X, keep system time as UTC. Rather than having a single timezone set for the whole computer, timezone offsets can vary for different processes. Standard library routines are used to calculate the local time based on the current timezone, normally supplied to processes through the TZ environment variable. This allows users in multiple timezones to use the same computer, with their respective local times displayed correctly to each user. Timezone information is most commonly stored in a timezone database known as zoneinfo
Procedure - set the time zone on a per user basis
Open user ~/.bashrc or ~/.bash_profile file using a text editor such as and set up TZ environment variable. Append or SET TZ as follows:
export TZ="/usr/share/zoneinfo/{TIMEZONE-DIRECTORY}/{TIMEZONE_FILE}"
If your username is vivek and you would like to set TZ to Asia/Calcutta (INDIA IST) type the following command:
$ vi /home/vivek/.bashrc
OR
$ vi ~/.bashrc
Append the following line:
export TZ="/usr/share/zoneinfo/Asia/Calcutta"
Save and close the file. You can type the same command at bash shell prompt too:
export TZ="/usr/share/zoneinfo/Asia/Calcutta"
See also:
- Set the time zone system-wide using this /etc/localtime file
You should follow me on twitter here or grab rss feed to keep track of new changes.
Featured Articles:
- 30 Handy Bash Shell Aliases For Linux / Unix / Mac OS X
- Top 30 Nmap Command Examples For Sys/Network Admins
- 25 PHP Security Best Practices For Sys Admins
- 20 Linux System Monitoring Tools Every SysAdmin Should Know
- 20 Linux Server Hardening Security Tips
- Linux: 20 Iptables Examples For New SysAdmins
- Top 20 OpenSSH Server Best Security Practices
- Top 20 Nginx WebServer Best Security Practices
- 20 Examples: Make Sure Unix / Linux Configuration Files Are Free From Syntax Errors
- 15 Greatest Open Source Terminal Applications Of 2012

- My 10 UNIX Command Line Mistakes
- Top 10 Open Source Web-Based Project Management Software
- Top 5 Email Client For Linux, Mac OS X, and Windows Users
- The Novice Guide To Buying A Linux Laptop














{ 3 comments… read them below or add one }
The above steps don’t seem to work well.
Please check the link http://rai.amalji.com/timecheck.php
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~`
[root@ rai]# cat timecheck.php
<?php
echo “Present time in (India IST) is : “.date(“d D, M Y – h:i:s A”).”";
?>
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~`
[root@ rai]# ll .bash
.bash_profile .bashrc
[root@ rai]# cat .bash*
export TZ=”/usr/share/zoneinfo/Asia/Calcutta”
export TZ=”/usr/share/zoneinfo/Asia/Calcutta”
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~`
Please check the correct time comparisons from :
http://www.amalji.com/time
Fix:
Use php : http://rai.amalji.com/timecheck1.php
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~`
<?PHP
putenv(“TZ=Asia/Calcutta”);
echo “Present time in (India IST) is : “.date(“d D, M Y – h:i:s A”).”";
?>
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~`
I’d appreciate if you let me know what was wrong. :-)
Rai
Awesome Vivek. It works fine for me.
If I set TZ for my user, will my user’s crontab run at my new timezone, or the system timezone?