[英]Converting Unix time to GMT datetime with php
I use Instagram API and there is one important field there, created_time. 我使用Instagram API,其中一个重要字段created_time。 And those are in Unix timestamp format.
这些都是Unix时间戳格式。 I convert it to datetime with date('Ymd H:i:s',$insta_date);
我将其转换为带有date('Ymd H:i:s',$ insta_date)的datetime; (PHP) And it gives me normal datetime with GMT+0.
(PHP)它为我提供了GMT + 0的正常日期时间。 But i want it with GMT+3.
但是我想要GMT + 3。 Is there any shortest way to get GMT+N datetime from Unix timestamp?
有没有从Unix时间戳获取GMT + N日期时间的最短方法?
You can change the time to different timezone. 您可以将时间更改为其他时区。 The PHP function is:
PHP函数是:
date_default_timezone_set()
More info: http://php.net/manual/en/function.date-default-timezone-set.php 更多信息: http : //php.net/manual/en/function.date-default-timezone-set.php
You can use gmdate to get Greenwich Mean Time, and then add offset: 您可以使用gmdate获取格林威治标准时间,然后添加偏移量:
$offset = 3*60*60; // +3 hours
gmdate('Y-m-d H:i:s', $insta_date+$offset)
You can also use date to format a local time/date, if date_default_timezone_set is correct. 如果date_default_timezone_set是正确的,您还可以使用date格式化本地时间/日期。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.