How to convert user local timestamp to gmt timestamp [duplicate]

隐身守侯 提交于 2019-12-13 10:57:49

问题


Possible Duplicate:
Timezone conversion in php

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']);

For storing time/date into database, I use GMT timestamp.

After user submits a form with a date/time, I use strtotime or mktime to get the timestamp in user's local timezone.

How to convert user local timestamp to GMT timestamp?


回答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);


来源:https://stackoverflow.com/questions/9158501/how-to-convert-user-local-timestamp-to-gmt-timestamp

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!