Jump to content

Convert server time to local time


bulrush

Recommended Posts

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.

 

Link to comment
https://forums.phpfreaks.com/topic/213381-convert-server-time-to-local-time/
Share on other sites

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.

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.

 

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());

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.