S
S
Serezha Gromkov2015-12-17 22:50:05
PHP
Serezha Gromkov, 2015-12-17 22:50:05

How to get current time for zero timezone in php?

It is necessary to display the current time in each city, regardless of the time zone of the server and the user.
Example: I know that the time zone for Moscow is UTC+3. Wherever I am in the world, I must get the current time in Moscow. And it should not depend on the time zone set on the server.
I thought about this algorithm:

  1. Get current time for UTC0 - for zero zone
  2. Add or subtract hours for this city's time zone

So, I have a problem with the first paragraph. All functions return the time in the current time zone of either the server or the user. And I need a zero belt.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
K
Kirill Nesmeyanov, 2015-12-17
@sgromkov

The date object takes a time zone as the second argument, I suggest just specifying it: php.net/manual/en/datetime.construct.php

new \DateTime('now', new \DateTimeZone('Europe/London'));

K
Kirill Arutyunov, 2015-12-17
@arutyunov

gmdate returns GMT time

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question