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:
- This is done differently on a Unix server than a Windows server. If you want code compatible with both, you have to be careful
- Sometimes (especially in shared hosting situations) you aren't allowed to change the system time
- Changes to system time will remain after the script has executed unless you change it back later. Therefore you risk really screwing up the system clock.
If you want to change the time globally for an entire app, I recommend having a static variable $timeOffset
and create your own time()
function as follows:
function myTime(){
global $timeOffset;
return time()+$timeOffset;
}
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:
shell_exec("date 09-09-99"); // Use "date mm-dd-yy" or "time hh:mm:ss", respectively
In UNIX, according to the date
man page, the code would look like:
shell_exec("date 0909hhmm1999"); // It says "date MMDDhhmiYYYY". I'm not sure how to set seconds, although I assume "mi" = "minutes"