note 48546 added to function.time
| From: | webmaster at protonage dot net | Date: | Wed, 29 Dec 2004 04:59:13 +0000 |
| Subject: | note 48546 added to function.time | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-82433@lists.php.net to get a copy of this message | ||
Many people have asked me what's an easy way to implement time-stamp time-zone offsets.
Here's a simple class I made that has a function that returns a time-stamp calculated with a
time-zone offset argument.
<?php
class MyTimeZone {
const TIMEZONE_SERVER_OFFSET = -5; // your server's offset from GMT 0
public function timeOffset($offset = null)
{
if (is_int($offset)) {
$local_offset = $offset - self::TIMEZONE_SERVER_OFFSET;
return time() + 3600 * $local_offset;
}
return time();
}
}
$time = new MyTimeZone();
echo date('h:i:s a', $time->timeOffset(-8)); // finds GMT -8
?>
cheers.
----
Manual Page -- http://www.php.net/manual/en/function.time.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+48546
Delete -- http://master.php.net/manage/user-notes.php?action=delete+48546&report=yes
Reason: bad code -- http://master.php.net/manage/user-notes.php?action=delete+48546&report=yes&reason=bad+code
Reason: spam -- http://master.php.net/manage/user-notes.php?action=delete+48546&report=yes&reason=spam
Reason: useless example -- http://master.php.net/manage/user-notes.php?action=delete+48546&report=yes&reason=useless+example
Reason: contains commercial links -- http://master.php.net/manage/user-notes.php?action=delete+48546&report=yes&reason=contains+commercial+links
Reason: useless note -- http://master.php.net/manage/user-notes.php?action=delete+48546&report=yes&reason=useless+note
Reject -- http://master.php.net/manage/user-notes.php?action=reject+48546&report=yes
Search -- http://master.php.net/manage/user-notes.php