Search

On User-Defined Timezones in PHP

1 views

Understanding PHP’s Time Functions and the GMT Assumption

When developers talk about PHP’s date functions, the first images that usually come to mind are date() and mktime(). They’re simple to use, fast, and get the job done for a wide range of applications. However, underneath the surface lies a subtle rule that most people overlook: every timestamp in PHP is measured in seconds since the Unix epoch, which is defined in Greenwich Mean Time (GMT). That means the numeric value returned by mktime() is not a time in the local server zone, but a universal instant that can be converted into any zone on demand.

Let’s break down the math with a small experiment. Suppose your server runs on Eastern Time (UTC−5) and you ask PHP to create a timestamp for midnight on January 1, 1970:

Prompt
<?php</p> <p>echo mktime(0, 0, 0, 1, 1, 1970);</p> <p>?></p>

Suggest a Correction

Found an error or have a suggestion? Let us know and we'll review it.

Share this article

Comments (0)

Please sign in to leave a comment.

No comments yet. Be the first to comment!

Related Articles