mysql设置时区
mysql_query("SET time_zone = '+8:00'") or die('时区设置失败,请联系管理员!');
中国在东8区所以加8
方法二:
select count(user_id) as device,CONVERT_TZ(FROM_UNIXTIME(reg_time),'+08:00','+00:00') as date from user_server where reg_time!='0' and reg_time between '1416268800' and '1416441599'and server_id = '1001' group by date;
◆ CONVERT_TZ(dt,from_tz,to_tz)
CONVERT_TZ() 将时间日期值dt 从from_tz 给出的时区转到to_tz给出的时区,然后返回结果值。
函数:FROM_UNIXTIME
作用:将MYSQL中以INT(11)存储的时间以"YYYY-MM-DD"格式来显示。
语法:FROM_UNIXTIME(unix_timestamp,format)