$dt = new DateTime('tomorrow 09:00:00');
echo $app->make('helper/form/date_time')->datetime('dt', $dt, false, true, null, 1800, array());
shows the correct date and time only if the system server time is the same as the user's, e.g. localhost. But if the server and user are in different time zones, the $dt at the user end is no longer that.
I also tried:
$dt = $dh->formatDateTime(date("Y/m/d H:i:s"), false, false, 'user');
which shows the current user date and time, but as soon as I change anything in there (like adding a day or time or anything, it goes back to the server's datetime).
For example, the above shows today's 17/08/18 1:00 (correct user time now), but
$dt = $dh->formatDateTime(date("Y/m/d H:i:s", strtotime("tomorrow 9:00")), false, false, 'user');
shows 18/08/18 1:00 which is 9:00 - 10 h for time zone = server time.
How can I show that exact date and time (tomorrow 9:00) as the user's, not as the system's?
You can use the following solution:
This will give you the browser's time zone in
timezone
. You need to pass that to the backend and use it to adjust the time for the user. Below, the value oftimezone
above has been stored in$timezone
.