douqi0090 2018-04-06 12:42
浏览 117
已采纳

时区与碳的区别

Time in CEST = UTC time+2h but my code showing only 1h and I don't know why... (you can test it here )

require 'Carbon/Carbon.php';
use Carbon\Carbon;

$timestamp = '2018-04-06 14:30:00';
$date = Carbon::createFromFormat('Y-m-d H:i:s', $timestamp, 'UTC');
var_dump($date);
//{ ["date"]=> string(26) "2018-04-06 14:30:00.000000" ["timezone_type"]=> int(3) ["timezone"]=> string(3) "UTC" } 
$date->tz('CEST');
var_dump($date);
//{ ["date"]=> string(26) "2018-04-06 15:30:00.000000" ["timezone_type"]=> int(2) ["timezone"]=> string(4) "CEST" }
  • 写回答

1条回答 默认 最新

  • doujiao3072 2018-04-06 13:11
    关注

    The issue is that CEST is not a supported timezone in PHP, and can therefore exhibit "undefined behaviour". I suspect it's being interpreted as CET, which is UTC+1.

    If you use a specific geographical identifier instead, such as Europe/Berlin, it should present the correct result (i.e. +2 hours from UTC). Try:

    $date->tz('Europe/Berlin');
    

    See https://3v4l.org/c4lve

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 如何用Labview在myRIO上做LCD显示?(语言-开发语言)
  • ¥15 Vue3地图和异步函数使用
  • ¥15 C++ yoloV5改写遇到的问题
  • ¥20 win11修改中文用户名路径
  • ¥15 win2012磁盘空间不足,c盘正常,d盘无法写入
  • ¥15 用土力学知识进行土坡稳定性分析与挡土墙设计
  • ¥70 PlayWright在Java上连接CDP关联本地Chrome启动失败,貌似是Windows端口转发问题
  • ¥15 帮我写一个c++工程
  • ¥30 Eclipse官网打不开,官网首页进不去,显示无法访问此页面,求解决方法
  • ¥15 关于smbclient 库的使用