Timezone Setting Topic is solved

General project discussion. NOT for help questions.
nuspace

Timezone Setting

Post by nuspace »

Is there a way to set the timezone for CMS without hacking the code? I notice it seems to be using the server's timezone, but I'd like to be able to host multiple sites (with varying timezones) on the one server.

Any tips would be much appreciated.
Ted
Power Poster
Power Poster
Posts: 3329
Joined: Fri Jun 11, 2004 6:58 pm

Re: Timezone Setting

Post by Ted »

What really shows the time, except for the News module?
nuspace

Re: Timezone Setting

Post by nuspace »

Exactly :). Well, that and the admin log, which isn't too big of a deal.

So is there a way to specify the time zone for the News module then? I noticed that RSS feeds look like they're published in UTC, which is okay because the RSS reader would figure things out. But if I'm not mistaken the articles themselves seem to reflect the server's time zone?
Ted
Power Poster
Power Poster
Posts: 3329
Joined: Fri Jun 11, 2004 6:58 pm

Re: Timezone Setting

Post by Ted »

To be honest, I don't know an easy way of doing that that I'm aware of...

There would have to be some kind of offset made with mktime, I think.
nuspace

Re: Timezone Setting

Post by nuspace »

Okay, I'll try to work something out, but any solution I find would probably be just a hack. I think to do it properly this would really need a field in the db and an admin setting. Then anything that reads or displays dates would have to take the tz into account.
Ted
Power Poster
Power Poster
Posts: 3329
Joined: Fri Jun 11, 2004 6:58 pm

Re: Timezone Setting

Post by Ted »

I agree that it's probably a good idea.  If you give me some hints on how to modify the dates, I can probably fit that in somewhere.
nuspace

Re: Timezone Setting

Post by nuspace »

The simplest way I can think of is to store all timestamps in GMT. So whenever you call mktime(), subtract the offset in seconds from the timestamp. Conversely, whenever you read a timestamp from the database, add the offset. This way, the user can change their timezone any time and it would still display the correct time.

Internally, the offset is probably best stored in minutes rather than hours, as there are timezones that are a half or even a quarter of an hour off.
trick

Re: Timezone Setting

Post by trick »

Use the 'Z' setting on the date function:

http://www.php.net/date
EsquireX

Re: Timezone Setting

Post by EsquireX »

I, too, am attempting to change the timezone on my site only because I want to display the current date and time on my main page. Is this possible?
SimonSchaufi

Re: Timezone Setting

Post by SimonSchaufi »

in other CMS it is working like in Joomla. (http://www.joomla.de)
I will be happy to see the same function in the next version!

In my case: My Website is for Nigeria but the Server is in USA. the time is the one in USA (-7 hours) and not the one in Nigeria.

This is the solution:

$timezone  = 1; //(GMT -5:00) EST (U.S. & Canada) The user can set different values here
echo gmdate("d.m.Y H:i:s", time() + 3600*($timezone+date("I")));

date("I") is for summer and winter time and the user should also choose if he is in a country with summer and winter time or not

See http://de3.php.net/manual/en/function.gmdate.php
Last edited by SimonSchaufi on Wed May 02, 2007 7:18 pm, edited 1 time in total.
User avatar
Nullig
Power Poster
Power Poster
Posts: 2380
Joined: Fri Feb 02, 2007 4:31 pm

Re: Timezone Setting

Post by Nullig »

I posted a script here:

http://forum.cmsmadesimple.org/index.ph ... 469.0.html

to do just that.

Nullig
st3ph3n
New Member
New Member
Posts: 5
Joined: Fri May 23, 2008 1:05 am

Re: Timezone Setting

Post by st3ph3n »

Anyone have any luck with this? Sorry if this has been answered elsewhere (or here and I don't understand it!)
I have a server in the states, with my site designed for NZ. We have the News and Calendar modules, I don't care too much about news but the Calendar module relies on the server time, so the current day is often wrong. Is there any way to offset the master clock to line up with us? (GMT+12)
User avatar
Nullig
Power Poster
Power Poster
Posts: 2380
Joined: Fri Feb 02, 2007 4:31 pm

Re: Timezone Setting

Post by Nullig »

If you have access to the .htaccess file, you could try adding:

SetEnv TZ Pacific/Auckland

or

SetEnv TZ NZ

Not sure which one is correct...

Nullig
Last edited by Nullig on Thu May 29, 2008 5:45 am, edited 1 time in total.
st3ph3n
New Member
New Member
Posts: 5
Joined: Fri May 23, 2008 1:05 am

Re: Timezone Setting

Post by st3ph3n »

Awesome, I think that did it! :-)
Thanks!
(I used SetEnv TZ Pacific/Auckland)
delfstrom

Re: Timezone Setting

Post by delfstrom »

On my host it didn't work the .htaccess file, but I was able to overcome this by adding the following line to config.php (I put it under the locale setting line)

putenv('TZ=US/Eastern');

Works just fine in the news date/time etc. Change according to your own timezone.
Post Reply

Return to “General Discussion”