Get timezone offset in PHP given unix timestamp

I have a Unix timestamp that comes from a database that (unfortunately) is in the time zone with a specific amount of +3600 or +7200, depending on whether it is DST or not. This has never been a problem before, but our website is currently moving to a more international audience and due to interaction with Javascript with the specified timestamps, I need to convert the timestamp without any bias.

So, how do I, given only the Unix timestamp, get the offset for the time zone at the time of this timestamp? I am looking at PHP docs, but there are so many date / time functions that I lost a bit.

I am using PHP 5.2.3

+3
source share
5 answers

I feel stupid again when I answer my question, but I just found gmstrftime. I seem to be doing exactly what I want. Thanks to everyone though!

+4
source

You cannot do this in the general case. Unix timestamp is just the number of seconds since Unix and does not contain any timestamp information.

, , , , DST, . ( , ).

, , UTC, .

+2

unix unix ( Epoch), 0. 00:00:00 UTC, 1 1970 . UTC, 0.

dst , unix /. ( php, C, localtime unix, , /etc/localtime, , , ..).

+2

U :

$timezone_offset = date('O');

(GMT) .

[]

+1
0

Source: https://habr.com/ru/post/1719600/


All Articles