I make a project and its only with php and I want to get real time. I trying with date()
, time()
and others but It isnt real it is 1+ or 1- hours. Please tell me how to see the real time with $varible
.

- 2,972
- 3
- 27
- 39

- 35
- 1
- 7
-
Real time.... where? – Jonnix Oct 28 '16 at 14:47
-
Possible duplicate of [How to get the current date and time in PHP?](http://stackoverflow.com/questions/470617/how-to-get-the-current-date-and-time-in-php) – Phiter Oct 28 '16 at 14:47
-
How the heck does `time()` give you +1 or -1 hour? It's a timestamp. Timestamps have no knowledge of timezones. Your problem lies somewhere else. – Andrei Oct 28 '16 at 14:48
-
On the page... because I whant to make table with date and hours... – Tony Markov Oct 28 '16 at 14:48
-
Make sure you set the correct timezone. – Laurent Meganck Oct 28 '16 at 14:48
-
But I want to show user default time if he is in Sofia, Bulgaria to show there what is the time and if he goes in the New York to see there default time – Tony Markov Oct 28 '16 at 14:57
2 Answers
Because PHP is a server side language you will get the time of the server, not of the client. So for example if you have a server in Europe and you are in USA you will get the time in Europe.
To get the time in a specific timezone you can add before:
date_default_timezone_set('America/Los_Angeles');
After that the date will be in that timezone.
echo date("Y-m-d H:i:s");
UPDATE
You can't simply detected from what timezone is the client that loaded your page, but on your server you receive the IP
address of the client and using this IP address there are some tools that can return the location of the client and then you need to translate that to a format accepted by PHP. So it's not so easy. The easy way to display the client exact time is do to this in JavaScript, because that runs on client's local browser and will be the time of the computer.

- 2,972
- 3
- 27
- 39
I think you must change the time zone, you can do it in this way:
<?php
date_default_timezone_set('America/Los_Angeles');
?>
You can read more about it in here Also you can find the available time zones in here
Best regards.

- 79
- 1
- 11
-
But I want to show user default time if he is in Sofia, Bulgaria to show there what is the time and if he goes in the New York to see there default time – Tony Markov Oct 28 '16 at 14:54