For a simple PHP graphing script, I need to align time values at local time days. When I do something like $timestamp % 86400 == 0
I get a break at 2 am every day because I'm in UTC +2 here. Also all my grid lines are at 2am, 5am, 8am etc. instead of 0am, 3am, 6am etc.
I understand that UNIX timestamp integer values are always in UTC and that there's date()
and gmdate()
and such, but I need an integer in local time to do arithmetics on it. How would I do that in PHP? Is there a function such as ToLocalTime()
and ToUniversalTime()
like in .NET?
To clarify the question, I have nothing to do with readable formatting of the time. No YYYY-MM-DD HH:MM:SS or the like, I just deal with numbers. The input is a number of seconds since epoch in UTC, aka the UNIX timestamp. What I need is a number of the same kind but not in UTC but local time. So I need to convert a UNIX timestamp integer into a local timestamp integer. Hope this is understandable and anybody can imagine what this could be used for (aligning grid lines in a time-axis graph at local time).