Hello At sign-up, I collect the user's country and set the nearest timezone (they can change this if it is incorrect). I want to display time local to a user. How can this be done? Thanks
this is how I personally do it. it just gives you a brief on the calculations, you can do it your own way $t_ime = the timestamp ( time() ) stored in the db so if you want just the current time then $t_ime = time(); $this->tzone is a number I believe since times are set at GMT0 for example GMT+1, tzone would be 1 or GMT-10, tzone would be -10 and eh, I'm not too sure what else to say really. I wrote this three years ago when I was 15... but it's always worked for me edit //set this to whatever timezone the user is in. for example -10, 11, -3 ect.. $Tz = -10; //set timezone date_default_timezone_set('Europe/London'); //Current server time $Current = time(); //Work out $add = ($Tz * 3600); //Work out timezone $Current = $Current + $add; //show local time $result = date('M d, Y H:i', $Current); Code (markup):
You have to use javascript or actually ask the user what their timezone is. There is no server side method of determining this, as the user's browser does not pass this information in a page request. You can also use a geoip database to get closer, but it's not exact.