开发者

Changing MySQL server timing for one website

I have one website which does not use US timings. Is it possible to change PHP and MySQL timings for one websi开发者_如何学Gote? If so what do I need to do?


you can do it per connection , when you start connection to this website set it,

look at :

http://dev.mysql.com/doc/refman/5.6/en/time-zone-support.html

#

Per-connection time zones. Each client that connects has its own time zone setting, given by the session time_zone variable. Initially, the session variable takes its value from the global time_zone variable, but the client can change its own time zone with this statement:

mysql> SET time_zone = timezone;

but be aware that :

The current session time zone setting affects display and storage of time values that are zone-sensitive. This includes the values displayed by functions such as NOW() or CURTIME(), and values stored in and retrieved from TIMESTAMP columns. Values for TIMESTAMP columns are converted from the current time zone to UTC for storage, and from UTC to the current time zone for retrieval.

The current time zone setting does not affect values displayed by functions such as UTC_TIMESTAMP() or values in DATE, TIME, or DATETIME columns. Nor are values in those data types stored in UTC; the time zone applies for them only when converting from TIMESTAMP values. If you want locale-specific arithmetic for DATE, TIME, or DATETIME values, convert them to UTC, perform the arithmetic, and then convert back.

an example how to set is in :

http://www.electrictoolbox.com/mysql-set-timezone-per-connection


For PHP:

<?php
    date_default_timezone_set('Europe/London');
?>

See the list of PHP supported timezones here: http://www.php.net/manual/en/timezones.php

For MySQL you'll need to execute query like this:

SET time_zone = timezone;

See detailed information in the MySQL documentation: http://dev.mysql.com/doc/refman/5.1/en/time-zone-support.html


Yes, you should do all time zone conversions inside PHP, not mysql.

For each column in your database which stores a date/time, either

a) Store it in GMT and do the necessary conversion OR

b) Store it in local time always

In neither case does MySQL need to know, but your developers do so be sure that you document this in your schema if you have a mixture.

It is often necessary to store local time date/time values. MySQL does not remember a time zone in a datetime column (nor could it easily; other DBs attempt to in some cases).

If you are storing a precise point in time which has already happened (e.g. now) then you should always store it in UTC to avoid confusion about when exactly it happened. Some apps use epoch / unix time for this purpose.

A future time you may have to store in local time because you can't tell (yet) exactly what time it will have to happen, that may depend on the decision of politicans who might not have been elected yet.

Time zones are tricky things because politicians control them. They tend to change with little warning (typically only a few years)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜