3.3. Converting an Epoch Timestamp to Time and Date Parts

Problem

You want the set of time and date parts that corresponds to an epoch timestamp.

Solution

Pass an epoch timestamp to getdate( ) :

$time_parts = getdate(163727100);

Discussion

The time parts returned by getdate( ) are detailed in Table 3-1. These time parts are in local time. If you want time parts in another time zone corresponding to a particular epoch timestamp, see Recipe 3.12.

See Also

Recipe 3.3 for how to convert time and date parts back to epoch timestamps; Recipe 3.12 for how to deal with time zones; documentation on getdate( ) at http://www.php.net/getdate.

Get PHP Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.