如何将用户本地时间戳转换为gmt时间戳

时间:2012-02-06 10:10:08

标签: php datetime timezone timestamp

  

可能重复:
  Timezone conversion in php

当用户登录时,我将他/她的本地时区保存在会话中,并将默认的php时区设置为:date_default_timezone_set($_SESSION['timezone']);

为了将时间/日期存储到数据库中,我使用GMT时间戳。

用户提交带有日期/时间的表单后,我使用strtotime或mktime在用户的本地时区中获取时间戳

如何将用户本地时间戳转换为 GMT时间戳

1 个答案:

答案 0 :(得分:1)

$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);
相关问题