如何在mysql中将时间戳更改为我自己的时区?
以下是我的PHP代码:
$sql = "CREATE TABLE `mytable` (
`id` int(6) unsigned not null auto_increment,
`firstname` varchar(30) not null,
`lastname` varchar(30) not null,
`email` varchar(50),
`reg_date` timestamp not null default CURRENT_TIMESTAMP on update CURRENT_TIMESTAMP,
PRIMARY KEY (`id`)
) ";
答案 0 :(得分:0)
对于单个表和列,您可以创建一个视图,当您从视图而不是表本身中进行选择时,只将时间戳列从服务器的时区转换为实际时区。
CREATE VIEW `v_mytable` AS
select id
,firstname
,lastname
,email
,CONVERT_TZ(regdate,'UCT','US/Pacific') as regdate
from mytable;
如果您没有安装CONVERT_TZ,请在此处概述如何安装它: MySQL CONVERT_TZ()