【问题标题】:get actual date in unix timestamp and the convert it to gmt-3 in php在 unix 时间戳中获取实际日期并将其转换为 php 中的 gmt-3
【发布时间】:2015-08-17 19:57:33
【问题描述】:

我需要获取当前的 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?

日期快把我逼疯了,请帮忙

【问题讨论】:

    标签: php codeigniter date timezone timezone-offset


    【解决方案1】:

    希望下面的例子对你有所帮助。

    $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
    

    【讨论】:

      猜你喜欢
      • 2016-09-03
      • 1970-01-01
      • 2021-02-19
      • 2013-06-01
      • 2016-11-12
      • 1970-01-01
      • 2011-06-20
      • 2013-05-28
      • 2020-10-19
      相关资源
      最近更新 更多