Jump to content

Archived

This topic is now archived and is closed to further replies.

daniel244rock

Display proper time with date(). Minus 2 hours from server time sitewide.

Recommended Posts

I have a rather large project written, taking in about 200 pages.  Everything was working peachily. 
Then I switched hosts to be on a faster server, but the new server is in a different time zone than my old one.  All my date() commands change to the next day at 10:00 PM, 2 hours ahead of schedule. Sadly, I didn't take this into account when I coded these pages or I could have put in a var that I could set and they'd all be updated.

Is there a way I can subtract 2 hours from the server time sitewide?  Or do I have to go though each page and strtotime("-2 hours") each one?  Or is there another way to do this?

Thanks much!

Daniel

Share this post


Link to post
Share on other sites
The solution I used depended on:
1. all calls for a timestamp were to the date(..) function.
2. there were no other calls that looked like the date(..) pattern
3. I had an INCLUDE file that was included in all routines

What I did was:
1. a global change of my routines and changed all date(..) calls to my_date(..)
2. in the INCLUDE file I added the following routine (you'll have to change it to suit your needs).
First parm is display pattern, second one is offset to GMT (thanks to cHuAyW2o0o)

[code]<?php
function my_date($pattern, $offset) {
// $offset = "2";// Hour for offset to GMT time zone goes here e.g. +7 or -4
  return gmdate($pattern, time()+($offset * 3600));
}
echo "Your current time now is : ". my_date("m/d/Y g:i:s A", 2);
?> [/code]

Hope this gets you on your way!

Ronald   8)

Share this post


Link to post
Share on other sites
HaHa!!  That is perfect!

Thank you so much for the excellent response.  My scripts meet all the criteria you listed and the solution worked flawlessly.  And so easy to update if I ever change hosts again.

Thanks Ron

Daniel

Share this post


Link to post
Share on other sites
The good thing is: you don't have to change this when you change hosts! It uses an offset to the standard GMT time and that never changes (probably).

Ronald  8)

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.