Change system time for UNIX process? Change system time for UNIX process? unix unix

Change system time for UNIX process?


Well, I found the answer by myself.

In unix shell there is an environmental variable TZ which is the timezone and it is used by all C/C++ time functions.

This variable can be manipulated to set time in current unix shell to any arbitrary time (limited to number of seconds, not milliseconds) and even change date.

Examples:

export TZ=A-02:10:20

(shifts time by 2 hours 10 minutes and 20 seconds from now forward).

export TZ=A+02:10:20

(the same shift backwards)

If you want to change the date, you can use large number of hours, for example:

export TZ=A-72:10:20

Unfortunately it does not let you change date too much, from my experiments it is up to several days back/forward. So for changing month/year this does not work.

(use 'date' command to check current date/time after setting TZ variable).

To cancel all changes use

export TZ=