new Date().getTime(). I send the action log to the server, which uses
$dt = date('h:i:s', timestamp / 1000) to get a human-digestable time. (Note that for printing purposes I'm only interested in time element, but I need to store the full date/time in the database for later audits.)
My clients can be located anywhere in the world. What I noticed is that when I call
date on the timestamp received from the client, the server applies the timezone offset of where the server is located (most likely, the default timezone from
php.ini). Thus, if the client in London is passing a timestamp for 10:00:00, the server-printed time ends up being 2:00:00, as the server is in California.
I can easily send the timezone UTC offset with the data (i.e. the value of
new Date().getTimezoneOffset()). However I don't quite understand how I should use this timezone offset to get the right printout for the client. It's probably going to be some sort of combination of getting the defualt tz and using the tz from the client - but I just can't get my head around it.
All I want is that the timestamp for 10:00:00 be displayed as 10:00:00 regardless of where the client is or a server is.