:: RootR ::  Hosting Order Map Login   Secure Inter-Network Operations  

Code examples to customize your timezone on rootr.net servers

By default rootr.net's servers are all set to UTC (aka GMT or Greenwich Time), so all is synchronized around the planet. All rootr.net's servers are synchronized automatically to standard NIST time. If you want time as it is where you live, How to set the Time Zone for your specific location ?

This is simply done by exporting the TZ envronment variable. Many software programs supporting Time Zones and international time formats, make use of this setting. It takes care of the hours and minutes offsets, of the winter time offset policy (which changes from a country to another), and also of the Date shift (plus or minus one day).

The full list of all possible timezones is the content of the directory /usr/share/zoneinfo/ Here are some typical example how to set this TZ for you. replace "America/New_York" with the appropriate timezone

Bourne shell family, such as sh, bash, Korn shells, and also Zsh: export TZ=America/New_York
C-Shell, csh and tcsh: setenv TZ America/New_York
From a perl script: $ENV{TZ} = "America/New_York";
%ENV is a global hash, directly tied to the environment.
From a ruby script: ENV["TZ"] = "America/New_York";
This affects the environment directly.
From a python script: import os
os.environ["TZ"] = "America/New_York"
In Standard C: #include <stdlib.h>
putenv("TZ=America/New_York");


Or better and safer:
#include <err.h>
#include <stdlib.h>
if (setenv("TZ", "America/New_York", 1) < 0)
      err(1, "could not set TZ env");
From inside PostGreSQL: SET TIME ZONE "America/New_York";
To display it: SHOW TIME ZONE;
See also:
SQL syntax for SET
Date-time support in PostGreSQL
Time zone list from PostGreSQL's manual.
rootr.net's PostGreSQL FAQ
From a PHP script: putenv("TZ=America/New_York");
From Inside MySQL: There is no easy way to set TZ, even in recent versions. Some future version may paliate this. Nethertheless, your application can rely on rootr.net's server timezone being consistent. Altougth it cannot be set from inside, the timezone can be retrieved from the variables list:
SHOW VARIABLES;

Users running their own mysqld server can set TZ with the shell, typically when starting safe_mysqld.

 
::  Contact Information   ::   ©2024 ROOTR ::  


taintator@RootR.net