About Linux FAQ

Browse More FAQs:

Linux, UNIX set the time zone on a per user basis

Posted by Vivek Gite [Last updated: December 12, 2006]

Q. We are developing Linux based application and we would like to set the time zone on a per user basis for an individual user.

How do I configure Fedora Core Linux to set the time zone on a per user basis?

A. 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 vi text editor 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 command:
# vi /home/top/.bashrc
Append following
export TZ="/usr/share/zoneinfo/Asia/Calcutta"

Save and close the file.

See also

=> Set the time zone system-wide using this /etc/localtime file

Subscribe to our free e-mail newsletter or RSS feed to get all updates. You can Email this page to a friend.

Related Other Helpful FAQs:

Discussion on This FAQ

  1. Rai Says:

    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

  2. Vasudeva Says:

    Awesome Vivek. It works fine for me.

Leave a Reply

We encourage your comments, and suggestions. But please stay on topic, be polite, and avoid spam. Thank you very much for stopping by our site!

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

*
To prove you're a person (not a spam script), type the security word shown in the picture. Click on the picture to hear an audio file of the word.
Click to hear an audio file of the anti-spam word

Copyright © 2006-2008 nixCraft. All rights reserved - TOS/Disclaimer - Privacy policy - Sitemap - Powered by Open source software.