#native_company# #native_desc#

Compensate for server and user to return local time

By Allen
on October 12, 2004

Version: 1.0.0

Type: Function

Category: Calendars/Dates

License: GNU General Public License

Description: When developing scripts that display time, it can be tedious trying to manually compensate for the server (as well as desired zone) offset — especially when DST is an issue. This function will automatically compensate for the server time GMT deviation and then convert to the target time zone. This can be especially useful in user-driven scripts, if you wish to allow users to specify their own GMT offset.

The function can be used to convert any unix epoch time stamp, whether current time or an old forum post. It returns the time stamp, so you can format the date as you like externally. ( e.g. date(“r”,makeTime()); )

  $zone should reflect the GMT offset (e.g. -5)
  $dst should be a 1 if the target time should be offset
  for daylight savings time. It defaults to 0 (no dst)
  If no value is given for $time, the function will use the
  current time.  Otherwise, it accepts Unix Epoch timestamps

function makeTime($zone=0,$dst=0,$time=0) {
  if ( $time === 0 ) {
    $time = time();
  $time -= date("Z",$time);
  $time += $zone*60*60;
  if ( $dst > 0 ) {
    $time += 60*60;
  return $time;