Jump to content

PHP Local Time


Twango

Recommended Posts

Now, before you go "This guy's an Idiot" and move on, just hear me out.I've been trying to get this to work for hours.I've tried getdate(), date(), localtime(), and everything else I can find.Any time I try to return the hour, I get 6 hrs ahead of what I want to recieve,For example if it's 12:30, I get 6:30 PM.I can't have this at all.I need EACH user to return the time in THEIR time zone.For example, if a user in the EST time zone logs on at 4:00 PM EST, it shows that it is 4:00 PM. If someone in say, California logs on at the same time, (At 4:00 PM EST, or 1:00 PM PST) it shows 1:00 PM PST)I have no clue how to do this, for testing i'm just subtracting 6 hrs from the time...Any help?

Link to comment
Share on other sites

PHP does not know what time it is for the user because it runs on a different machine.Normally, in a system where the user has an account, they can select their timezone in their profile settings so that all times on the site show correctly for them.

Link to comment
Share on other sites

You can use date_default_timezone_set to set the timezone that PHP uses for its date/time functions. In order to get the user's timezone, since PHP doesn't know it, you need to use Javascript to get the user's current time or timezone offset and send that data to PHP, possibly with ajax, a cookie, or another method. If it's not necessary to use PHP at all, depending on what you're trying to do with the date, you could use Javascript only.

Link to comment
Share on other sites

Archived

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

×
×
  • Create New...