0

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.

Daniel Dudas
  • 2,972
  • 3
  • 27
  • 39
Tony Markov
  • 35
  • 1
  • 7

2 Answers2

2

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.

Daniel Dudas
  • 2,972
  • 3
  • 27
  • 39
0

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.

  • 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