I'm trying to make a commenting system like Stackoverflow has. The problem I'm facing is how to show the user the time of their and other comments in their local time (i.e., 2 hours ago) when my server running PHP and my MySQL database are storing the time often in a different time zone than the user.
I understand to keep local time on the server I have to use code like this (swapping out Europe/Zurich for wherever you are in the world):
$myTimezone='Europe/Zurich';
date_default_timezone_set($myTimezone);
I also understand to send the local $myTimezone
to my server I need to get the local time using Javascript in a manner like this (adapted from here):
var localDate = new Date(),
offset= -localDate.getTimezoneOffset()/60; //can send this 'offset' variable via $.ajax to the server
My question is instead of writing date_default_timezone_set($myTimezone);
on everyone of my PHP scripts that spits out the time (ultimately more places than just for the commenting system), is it possible to globally set the localtime on my server somehow?