如何将用户本地时间戳转换为gmt timestamp [英] how to convert user local timestamp to gmt timestamp
本文介绍了如何将用户本地时间戳转换为gmt timestamp的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
可能重复:
php中的时区转换
当用户登录时,我保存他/她的本地时区在会话中,并将默认的php时区设置为: date_default_timezone_set($ _ SESSION ['timezone']);
When a user logs in, I save his/her local timezone in session, and set the default php timezone to it: date_default_timezone_set($_SESSION['timezone']);
为了将时间/日期存入数据库,我使用GMT时间戳。
For storing time/date into database, I use GMT timestamp.
在用户提交带有日期/时间的表单后,我使用strtotime或mktime在用户的本地时区中获取时间戳
After user submits a form with a date/time, I use strtotime or mktime to get the timestamp in user's local timezone.
如何转换用户本地时间戳到 GMT时间戳?
推荐答案
$second = gmdate('s', $timestamp);
$minute = gmdate('i', $timestamp);
$hour = gmdate('H', $timestamp);
$day = gmdate('d', $timestamp);
$month = gmdate('m', $timestamp);
$year = gmdate('Y', $timestamp);
$gmt = mktime($hour, $minute, $second, $month, $day, $year);
这篇关于如何将用户本地时间戳转换为gmt timestamp的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文