PHP: Are timezone data embedded in Timestamps in some way?
date_default_timezone_set("Asia/Singapore"); // UTC +8
$dt = new DateTime();
$dt->setTimestamp(DateTime::createFromFormat('u', gmdate('u'))->getTimestamp());
echo $dt->getTimezone()->getName(); // Asia/Singapore
echo $dt->format('d M Y H:i:s'); // Correct local time
$dt->setTimezone(new DateTimeZone('UTC'));
echo $dt->format('d M Y H:i:s'); // Correct UTC Time
die;
I am wondering if the timestamps contain temporary data. On line 3, you see what I used gmdate(), which should give me UTC / GMT. But when I get the time zone and datetime format, they fall into local time. I have not set timezones in my object yet DateTime, I gave it a UTC timestamp. It somehow knew that it was necessary to switch to local time. This makes me wonder if Timezone data is included in timestamps.