繁体   English   中英

在unix时间戳中获取实际日期,并在php中将其转换为gmt-3

[英]get actual date in unix timestamp and the convert it to gmt-3 in php

我需要获取当前的unix时间戳,然后将其转换为当地时间,即GMT-3,布宜诺斯艾利斯。

我做了一些研究,但我找不到符合我问题的帖子。

要问我的实际日期:

  $date = new \DateTime();

返回此日期对象:

 object(DateTime)[28]
 public 'date' => string '2015-06-03 11:06:18.000000' (length=26)
 public 'timezone_type' => int 3
 public 'timezone' => string 'America/Buenos_Aires' (length=20)

我可以访问timezone_type吗? 如果我做$ date-> timezone_type,它会给我错误

以及如何将unix时间戳转换为gmt-3?

日期让我发疯,请帮忙

我希望下面的例子可以帮到你。

$day = date('Y-m-d', time());
$date = new DateTime($day, new DateTimeZone('Pacific/Nauru'));
echo $date->format('Y-m-d H:i:sP') . "\n";

$date->setTimezone(new DateTimeZone('Pacific/Chatham'));
echo $date->format('Y-m-d H:i:sP') . "\n";

示例输出是

2015-06-03 00:00:00+12:00
2015-06-03 01:45:00+13:45

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM