PHP and MySQL timestamps and time zones

If I take the current timestamp using the NOW () function in MySQL, can I capture this field via php and provide this time in different time zones? Basically, converting the current time in the current time zone to another time zone?

+3
source share
2 answers

You can use the class DateTimeZone:

$gmt = new DateTimeZone("GMT");
$datetimeInGMT = new DateTime($now, $gmt);

It also takes up space in the form continent/city, for example. Europe/London.

If your datetime is not UTC, you can use setTimezone:

$datetimeInGMT = new DateTime($now, new DateTimeZone("America/New_York"));
$datetimeInGMT->setTimezone(new DateTimeZone("GMT"));
+5
source

MySQL , PHP. (EST, PST ..) , " " (America/Eastern). , , .

, , UTC, UTC_TIMESTAMP(). MySQL CONVERT_TZ() . http://dev.mysql.com/doc/refman/5.0/en/date-and-time-functions.html

. , . http://dev.mysql.com/downloads/timezones.html

+3

Source: https://habr.com/ru/post/1782987/


All Articles