Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

date_default_timezone_get()

Guest
Jan 31, 2011 Jan 31, 2011

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.

TOPICS
Server side applications
433
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Jan 31, 2011 Jan 31, 2011

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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Jan 31, 2011 Jan 31, 2011
LATEST

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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines