I have the problem which I assume isnt that uncommon in php; I need to display a timestamp in a browser that is local to the browser’s timezone (i.e. not local to the server).
Lets say for example that the browser is using EST. The timezone of the server is irrelevent since I will just use the unix timestamp (seconds since Jan 1st 1970) which is independent of zone. I can get the timezone of the browser with javascript, that is not an issue.
What I need is a function that can take a unix timestamp and a specific timezone and output it as a local time to that timezone. The date() function does this, except it assumes that the timezone to use is the timezone that the server is using. There is the option to use putenv(“TZ=EST”) to “temporarily” set the environment timezone variable to the timezone of the server before calling date() and it “should” only affect it for that script, but I really doesn’t seem safe to mess with environment variables.
I cant just add/substract a fixed number of seconds offset from the unix timestamp to correct this since that number is not really constant (ie EST is 5 hours off in the winter and 4 hours off in the summer) and I need to display past times from any part of the year in reports, which need to be correct and not an hour off if you skip over a daylight savings hump.
If anyone has a solution I would be very grateful.