Jump to content

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


daniel244rock

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
Link to comment
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)
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

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.