bulrush Posted September 14, 2010 Share Posted September 14, 2010 PHP 5.2.6 We rent PHP server space on a server in California. Several of my pages generated by PHP show the current date and time, so when the page is printed, the user knows when the data was printed. Our users could be anywhere in the US, I am in Michigan. How do I convert the server time (PDT) into local time, regardless of where the user is? Thanks. Quote Link to comment https://forums.phpfreaks.com/topic/213381-convert-server-time-to-local-time/ Share on other sites More sharing options...
AbraCadaver Posted September 14, 2010 Share Posted September 14, 2010 The most reliable an easiest is to out put it with JavaScript: alert(new Date().toString()); --or-- alert(new Date().toTimeString()); In PHP you can use date_default_timezone_set(), but you would still need to work out what timezone the user is in by using JavaScript or letting the user select their timezone. Quote Link to comment https://forums.phpfreaks.com/topic/213381-convert-server-time-to-local-time/#findComment-1111038 Share on other sites More sharing options...
bulrush Posted September 14, 2010 Author Share Posted September 14, 2010 Begin new to Javascript, how would I output that JS string to the browser? Instead of via a JS window? The browser is viewing a page which will be printed on paper, and the paper must have the local date and time on it. Quote Link to comment https://forums.phpfreaks.com/topic/213381-convert-server-time-to-local-time/#findComment-1111041 Share on other sites More sharing options...
AbraCadaver Posted September 14, 2010 Share Posted September 14, 2010 Begin new to Javascript, how would I output that JS string to the browser? Instead of via a JS window? The browser is viewing a page which will be printed on paper, and the paper must have the local date and time on it. document.write(new Date().toString()); Quote Link to comment https://forums.phpfreaks.com/topic/213381-convert-server-time-to-local-time/#findComment-1111047 Share on other sites More sharing options...
bulrush Posted September 14, 2010 Author Share Posted September 14, 2010 So, in PHP would it look like this? echo 'Date: '.<script>document.write(new Date().toString());</script>.'<br/>'; Or, how would I assign this string to a PHP variable? Thanks. I learn by asking questions. Quote Link to comment https://forums.phpfreaks.com/topic/213381-convert-server-time-to-local-time/#findComment-1111057 Share on other sites More sharing options...
bulrush Posted September 20, 2010 Author Share Posted September 20, 2010 Anyone know how to send a Javascript string and store it in a php variable? Quote Link to comment https://forums.phpfreaks.com/topic/213381-convert-server-time-to-local-time/#findComment-1113409 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.