Is it possible to change php’s current date and time (something like set_time(strtotime(‘1999-09-09’)) so when i call time() it will return me timestamp for 1999-09-09? I need to set it globally for whole app.
EDIT
I already have one old app and i need to make possible to set up current date.
I can’t accept any custom functions. Imagine i should review all the code and replace every time() call. Even if i’ll do so then it will not help because there are functions like getdate() which i need to replace as well.
The
time()functions actually asks the system clock for the time, so you’d have to update the time of the server’s system clock. A few things to keep in mind:If you want to change the time globally for an entire app, I recommend having a static variable
$timeOffsetand create your owntime()function as follows:If you’ve taken all of that into account and still want to change the system time, however, you would need to send a command to the shell using
shell_exec()In Windows, the code would look like this:
In UNIX, according to the
dateman page, the code would look like: