0

I am working on php apps where i am showing the current date like 22 (Day of month).Now i want to show the current day date of his country or area base not the server date.I searched for the solution and found this method date_default_timezone_set('America/New_York'); but this taking static area.How to get dynamic area with date of that ? Thanks in advance

Mahmood Rehman
  • 4,303
  • 7
  • 39
  • 76
  • If you'd like to show correct date and time for your visitors, first you should let each user to pick his timezone (or get it using javascript), then store user timezone in database or browser cookie, and finally set this timezone each time when user access pages. Considering, you store all dates for your website as timestamps, not strings. – umka May 22 '15 at 07:58

1 Answers1

0

The only ways you can get the users time zone or offset is by either asking the users or using Javascript. Asking the users is the best way if you already have user registration, then you can simply add a time zone field to the user database, and add a possibility to change it in the user management.

If you have no user registration, then you will need a drop down somewhere on the site, and a cookie where the selection is stored.

The alternative is to use Javascript to change the date on a page load. Then you need to substitute an offset from all the dates. To find out the clients offset see this question: Determine a User's Timezone .

Community
  • 1
  • 1
Lennart Regebro
  • 167,292
  • 41
  • 224
  • 251