I got the impression that the format () function of the PHP DateTime class exported the timestamp that it originally passed with the correct offset applied to it.
I realized that it does not make sense to do this. Therefore, I want to save the timestamp from the database (UTC) in the object along with the user time zone and be able to display it according to whether I want to have a UTC date or adjusted date of the user time zone.
I started extending the DateTime class to do this, but I am wondering if I am missing something in the existing methods in DateTime or in the decision-making process, why the DateTime class works the way it does.
Presumably, I will also need some static factory methods that can take a timestamp, timezone, and whether the timestamp has passed, is it a user-adjusted timestamp or a UTC timestamp, and be able to make the necessary adjustments to create an instance of the standardized DateTime object from the version UTC elapsed time. That way, I could create timestamps around the user interface and database and be able to convert between them accordingly.
Is there an easier way? I saw the date_default_timezone_set function, but I want this parameter not to affect the whole script, which leads to the fact that the time adjusted by the user was stored in the database.
(I store user timestamps in the database as a time zone string, for example, Europe / Berlin, to go to functions from the user session variable. I also intend to store all the data in UTC and leave the php.ini server also set to UTC.)
source share