• Hi, Pleskians! We are running a UX testing of our upcoming product intended for server management and monitoring.
    We would like to invite you to have a call with us and have some fun checking our prototype. The agenda is pretty simple - we bring new design and some scenarios that you need to walk through and succeed. We will be watching and taking insights for further development of the design.
    If you would like to participate, please use this link to book a meeting. We will sent the link to the clickable prototype at the meeting.
  • (Plesk for Windows):
    MySQL Connector/ODBC 3.51, 5.1, and 5.3 are no longer shipped with Plesk because they have reached end of life. MariaDB Connector/ODBC 64-bit 3.2.4 is now used instead.
  • The Horde webmail has been deprecated. Its complete removal is scheduled for April 2025. For details and recommended actions, see the Feature and Deprecation Plan.

UTC time as same Europe/Berlin in PHP

R

RogerSik

Guest
Hello,

in the shell the time is displayed right. See:

Code:
# timedatectl
Local time: Wed 2018-03-21 14:45:41 CET
Universal time: Wed 2018-03-21 13:45:41 UTC
RTC time: Wed 2018-03-21 13:45:41
Time zone: Europe/Berlin (CET, +0100)
Network time on: yes
NTP synchronized: no
RTC in local TZ: no

But in PHP its always the UTC Time.

Example PHP script output:
Code:
object(DateTime)#1 (3) { ["date"]=> string(26) "2018-03-21 14:44:34.000000" ["timezone_type"]=> int(3) ["timezone"]=> string(13) "Europe/Berlin" } object(DateTime)#1 (3) { ["date"]=> string(26) "2018-03-21 14:44:34.000000" ["timezone_type"]=> int(3) ["timezone"]=> string(3) "UTC" }

Why is this happening? How can this be fixed?
 
I do not see an issue here. The "local time" is what the timezone is co-definining. UTC is 13.45, Berlin is 1h ahead of UTC so the local time is 14.45.
 
Yes the timedatectl shows it right but not the PHP Scripts.

Example WordPress:
UTC is 22.03.2018 10:42:52.
Local Time is 22.03.2018 11:42:52.

This result was created at 10:42 local time.

Or the php script above. Where both timezones has the same time (see bolded).

object(DateTime)#1 (3) { ["date"]=> string(26) "2018-03-21 14:44:34.000000" ["timezone_type"]=> int(3) ["timezone"]=> string(13) "Europe/Berlin" } object(DateTime)#1 (3) { ["date"]=> string(26) "2018-03-21 14:44:34.000000" ["timezone_type"]=> int(3) ["timezone"]=> string(3) "UTC" }
 
Your claim seems to be that the DateTime object in PHP should read the timezone that is set by its own setTimezone method and then automatically convert a time given to the timezone that is set by the method. But that is not what it does. It is an object that can handle datetime data, and it stores information that you want it to store. It does not automatically convert anything. You could set any time and timezone, and the object will return the setting.

To test whether PHP uses the correct time, you can use getdate() instead.
 
Back
Top