在本地时间显示MySQL时间戳 [英] Showing MySQL timestamps in local time

查看:168
本文介绍了在本地时间显示MySQL时间戳的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个MySQL数据库,其中很多数据都以时间戳记存储在UTC时间.

I have a MySQL database with a lot of data stored with timestamps all in UTC time.

当用户查询该数据库时,我希望他们能够在其本地时区中查看数据.

When a user queries that database, I want them to be able to view the data but in their local timezone.

我希望不必每次都计算偏移量并使用PHP代码更改时间戳.还有其他办法吗?

I'd prefer not to have to calculate an offset each time and change the timestamp with PHP code. Is there any other way?

推荐答案

您可以使用 localtime() 函数获取本地时间并从数据库中找到匹配的记录.

You can use localtime() function to get the local time and find the matching records from database.

这篇关于在本地时间显示MySQL时间戳的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆