PHP变更伺服器日期和时间 [英] PHP Change Server Date & Time
问题描述
如何使用php更改服务器时间?根据到目前为止的研究,我发现您可以使用exec()函数执行任何终端线.我要在该函数中输入什么内容,以将日期和时间更改为2013年11月24日12:38?
How do I change the server time using php? From my research so far, I found you can execute any terminal line with the function exec(). What do I put into that function to say change the date and time to November 24, 2013 12:38?
我必须在PHP中执行此操作的原因是我无法访问物理服务器,因此所有操作都必须远程进行.我在使用exec()之前已经设置了Cron Jobs,所以我也应该有权更改日期.
The reason I must do this in PHP is I do not have access to the physical server, so everything must be done remotely. I have set up Cron Jobs before using exec(), so I should have permission to change the date as well.
谢谢!
推荐答案
假设服务器正在Windows上运行,我相信您可以执行exec('time 12:38:00 PM')
和exec('date 11/24/2013')
.如果它是基于Linux的服务器,我认为您可以执行以下操作:exec('date -s "24 NOV 2013 12:38:00"')
.另外,您可能想看一下这个问题.我意识到这是不一样的,但是回答的人提出了一个很好的观点,即假设您这样做的话,不要在Linux中以root身份运行php.
Assuming the server is running on windows I believe you could do exec('time 12:38:00 PM')
and exec('date 11/24/2013')
. If it is a linux based server I think you can do something like this: exec('date -s "24 NOV 2013 12:38:00"')
. Also you might want to look at this question. I realize it isn't the same but the person who answered brought up a good point about not running php as root in linux, assuming you are doing so.
I used this link for linux and this one for windows.
这篇关于PHP变更伺服器日期和时间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!