Copy link to clipboard
Copied
Hello, Everyone:
Is there a way that I can place a date timezone according the user's machine?
Right now a client has their website hosted on a CST. Is there a way that when a datetime stamp gets logged into a database it shows according the user's timezone rather than the timezone of the hosted server.
Right now in the users page they are able to see when they last logged in. However, it records the CST when actually the user is in EST. I hope I am making sense in all this.
I just want to put a script such as "date_default_timezone_get()" if it is the right script to the top of all my pages that when ever a datetime stamp gets recorded in a database that it records as the users timezone rather than the hosted server. Is this possible or is this wrong looking at it? Or the timezone is set in the MySQL, if so, how?
Thanks everyone.
Copy link to clipboard
Copied
You certainly could pass the client date/time to the script to insert the local date. I wouldn't do it that way - much too confusing. Keep all of your date/time in the same timezone. I would insert the dates using MySQL now() - and would probably use GMT for a timezone.
Then you can either show the user his login time in GMT, or use a js function like getTimezoneOffset() to convert to the local client time.
Copy link to clipboard
Copied
I just realized that in David Powers book PHP Solutions first edition on page 392-393 "Setting the correct time zone".
The code
<?php ini_set('date.timezone','America/Toronto'); ?>
It works but I want to know how to make it work with Daylight Savings Time.
Get ready! An upgraded Adobe Community experience is coming in January.
Learn more