If I grab the current timestamp using the NOW() function in MySQL can I grab that field via php and give that time in different time zones? Basically converting current time in the current timezone to another timezone?
You can use the DateTimeZone
class:
$gmt = new DateTimeZone("GMT");
$datetimeInGMT = new DateTime($now, $gmt);
It also takes locations in the form continent/city
, e.g. Europe/London
.
If your datetime is non-UTC, you can use setTimezone
:
$datetimeInGMT = new DateTime($now, new DateTimeZone("America/New_York"));
$datetimeInGMT->setTimezone(new DateTimeZone("GMT"));
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With