Jump to content


Display User's Time for their Timezone


2 replies to this topic

#1 .CJ

    Young Padawan

  • Members
  • Pip
  • 114 posts
  • Gender:Male
  • Location:Leeds, UK

Posted 23 September 2007 - 03:30 PM

Hey,

I had a thought recently. My web host is based in America, so there servers time is five hours a head of my clock (I'm in UK) so when I display the time/date on the site, it'll be +5. How's it done so that the time is set to the user's selected timezone? Here's how I think I MIGHT do it...

User selects the timezone from a drop down list, and the value of each option is '0, 1, 2, 3... -1, -2, -3' etc. When you display the time/date on your website, on the PHP side of things, would you just add the POST variable to your time function?

[code]time()+$_POST['timezone']/code]
Or is it somewat more complex than that?

As always, if you can shed any light on this, it will be appreciated.

- Chris.

#2 dotbart

    Young Padawan

  • Members
  • Pip
  • 141 posts
  • Gender:Male
  • Location:Diepenbeek
  • Interests:Webdesign, Webdeveloppement, DJ, ...

Posted 23 September 2007 - 06:23 PM

time() + ($_POST['timezone']*3600)
would be more correct since time() counts in seconds ;-)
Save the timezone in a database aswell so your users don't have to enter their timezone's at all times if that wasn't your plan allready :-)

#3 rc69

    PHP Master PD

  • P2L Staff
  • PipPipPipPip
  • 3,827 posts
  • Gender:Male
  • Location:Here
  • Interests:Web Development

Posted 23 September 2007 - 10:53 PM

This is a frequently asked question, please use the forum search, or google, or refer to the PHP manual. Also note, JavaScript is often times useful for this (unless you're doing a membership system, in which case, stick with php).





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users