PDA

View Full Version : Help Adding Server Time to Footer


vantastic
07-10-2011, 11:27 PM
I'm trying to put the server time into the footer, so it would read something like this:

All times are GMT +8. The time now is 08:15 AM. | Server Time: 00:15 AM.

I found an article on how to do it for vb3.8 but it doesn't want to work. The article can be found here (https://www.vbulletin.com/forum/showthread.php/366454-Custom-time-phrase).

Thanks in advance.

kh99
07-11-2011, 12:03 AM
Try using this for the plugin code:
$server_time = date('h:i:s A');
vB_Template::preRegister('footer', array('server_time' => $server_time))


and then in the template:
<br />The server time is now {vb:raw server_time}.

vantastic
07-11-2011, 12:28 AM
Thanks kh99 - I'm at least now getting a result, albeit an incorrect one, or unexpected one.

Code in html is:
<div class="below_body">
<div id="footer_time" class="shade footer_time">{vb:rawphrase all_times_are_gmt_x_time_now_is_y} | Server Time: {vb:raw server_time} </div>

The result i'm seeing is:
All times are GMT +8. The time now is 09:18 AM. | Server Time: 08:18 PM

Server time should be 02:18 AM

Perhaps the server is running on a different timezone to GMT? Maybe I need to implement the timezone into the code you gave above?

kh99
07-11-2011, 12:37 AM
Yeah, I'm not sure, I just copied the code from that thread you linked to. Reading the docs for date() it seems like your server is probably not set to GMT. I suppose you could just add 6 hours worth of seconds to it, something like date('h:i:s A', time() + 6 * 3600);

vantastic
07-11-2011, 12:46 AM
Beautiful! That'll do the trick just nicely. Thanks for your help :)

kh99
07-11-2011, 12:53 AM
You're welcome. But apparently I misunderstood the docs - you should be able to use gmdate() instead of date() to get GMT.

vantastic
07-11-2011, 01:02 AM
Oh even better. Thanks again! :)