sark9012
sark9012

Reputation: 5747

Server is the wrong time

So I am from the UK and have hosting in the US. I contacted my host and said that my server time is set 6 hours behind GMT. They said I need to alter this in my CMS.

How would i go about doing this? Whenever i put now() i am getting the wrong time.

Never seen this before, could anyone offer any suggestions?

Upvotes: 5

Views: 7078

Answers (4)

Glycerine
Glycerine

Reputation: 7347

You can change the timezone using PHP

putenv("TZ=Europe/London");

or if that produces an error:

date_default_timezone_set('Europe/London');

Alternatively if you can gain access to your php.ini (maybe not due to your hosting)

date.timezone = "Europe/London"

Change the setting to the above and you should be ok. Additional to the above - you can set the php.ini with PHP

ini_set('date.timezone', 'Europe/London');

http://www.php.net/manual/en/timezones.europe.php


Edit:

In my rush to answer - you could write GMT instead of Europe/London

Upvotes: 10

gnarf
gnarf

Reputation: 106382

For MySQL - you can execute SET time_zone = 'GMT' before your queries to set the time zone time_zone config docs.

For PHP - you can execute date_default_timezone_set() using one of the supported timezones. You could also set the value using a .htaccess directive:

php_value date.timezone UTC

Upvotes: 1

jneves
jneves

Reputation: 1324

Use DateTime::setTimeZone to define the timezone. The documentation is in http://www.php.net/manual/en/datetime.settimezone.php

Upvotes: 0

Evernoob
Evernoob

Reputation: 5561

You could work out how many seconds you are in front of the location in the US the server time is set to and add this value to your timestamp to get the correct time.

For example, if the server is in New York then this is 18000 seconds behind London time. So, getting the correct date would be: <?php $now = date('d M Y', (time() + 18000)) ?>

Upvotes: 0

Related Questions