Find the answer to your Linux question:
Results 1 to 2 of 2
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1

    localtime() for a different timezone


    From a C program, how do I convert to local time when the TZ environment variable is set to UTC. (We want to keep our system in UTC, and only use local time in this instance.).

    I can do:

    #TZ=EST date

    from the command line and get the proper result. I don't want to call use a system system("TZ=EST date") call from my C program fearing it will be too slow. And I want to avoid calculating time myself.

    I have seen others setenv() to set the TZ environment variable from userspace then unsetenv() however, I worry that other processes (threads,etc) could ask for time when this is set to the local TZ.


  2. #2
    Linux Newbie
    Join Date
    Sep 2004
    Hav'nt got time to try and verify it but have a look at man pages for setenv and tzset (eg. set the TZ variable to something using setenv() and then call tzset() before calling localtime()).
    In a world without walls and fences, who needs Windows and Gates?

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts