DDEV - php 在 Windows 上的容器内有错误的 date/time

DDEV - php has the wrong date/time inside container on Windows

我正在使用 DDev 进行本地开发,并且我设置了一个站点,其中 php 认为日期是 2.5 天之前,例如目前我主机上的 time/date 是:

2020 年 3 月 11 日,4:42pm

但是当我用这个php查看页面时:

<?php
$date = date('F d Y h:i:s');
echo $date;
?>

我看到这个日期: 2020 年 3 月 9 日12:59

如何解决这个日期问题?

尝试添加 date_default_timezone_set

date_default_timezone_set("Asia/Bangkok"); 

替换您的时区

编辑 2020-03-13:Docker Desktop 2.2.0.4 for Windows 声称已修复此错误。

Fixed an issue where containers did not synchronize time with the host when the host machine wakes up from the sleep mode. Fixes docker/for-win#4526.

原回复:

这是在 Windows 上吗? Docker Windows 的桌面在最近的版本中遇到了问题,尤其是与睡眠或休眠主机有关的问题。解决方法的最佳方法似乎是 https://thorsten-hans.com/docker-on-windows-fix-time-synchronization-issue - 他推荐 PS 脚本(或在 Hyper-V 管理控制台中手动 disable/enable 时间同步):

# fix-docker-machine-time-sync.ps1
$vm = Get-VM -Name DockerDesktopVM
$feature = "Time Synchronization"

Disable-VMIntegrationService -vm $vm -Name $feature
Enable-VMIntegrationService -vm $vm -Name $feature

但您通常可以:ddev poweroff 然后 ddev start。您也可以 ddev poweroff 并重新启动 docker。

这甚至在 release notes for Docker Desktop for Windows 2.2.0.3.

In some cases, Docker containers do not synchronize time with the host when the host machine is put to sleep

查看 Docker 桌面 Windows 问题:

请注意 Docker 已经提供了一个私有边缘版本来测试它,任何阅读它的人都会通过测试它来帮助一切。 Link to current private edge release。 (请记住,从 Stable 切换到 Edge 意味着丢失所有 Docker 容器和卷,这意味着丢失 ddev 数据库。)