PHP Time based on user location

Status
Not open for further replies.

NSA

sudo apt-get thefuckout.tar.gz
Dec 9, 2011
715
86
Hello!

I've been trying to set it so PHP will display time formatted for the user using an application.
You see here:
f714cbb0e7975a9582e240e077847ace.png




This says I sent a message at "21:50" however, my time was at "02:50" when it was sent. Now, obviously this is because this was the server time, but how can I get PHP to put the time it was sent from the user "IN SERVER TIME" but display it in "LOCAL TIME"?

So, in the database, this would still be displayed as "21:50", but on my screen it would say "02:50".

If anyone can help me with this, It'd be greatly appreciated.
Thanks.
 

Ecko

23:37 [autobots] -!- eckostylez [[email protected]]
Nov 25, 2012
1,398
962
You can't get PHP to do it because PHP is executed by the server. You need to use JavaScript since it is executed by the browser (aka the client)

 

Markshall

Русский Стандарт
Contributor
Dec 18, 2010
2,638
2,393
It is possible to do it with PHP but eckostylez's solution seems better.

You can use a site such as or something to get a generic location of the user's IP address then use that to set the timezone using date_default_timezone_set();
 
  • Like
Reactions: NSA

NSA

sudo apt-get thefuckout.tar.gz
Dec 9, 2011
715
86
@m0nsta's solution seemed easy enough.
Problem resolved -- please close thread.
 
Status
Not open for further replies.

Users who are viewing this thread

Top