|
|
 |
gmmktime (PHP 3, PHP 4 , PHP 5) gmmktime -- 取得 GMT 日期的 UNIX 时间戳 说明int gmmktime ( [int hour [, int minute [, int second [, int month [, int day [, int year [, int is_dst]]]]]]])
和 mktime() 完全一样,只除了返回值是格林威治标准时的时间戳。
和 mktime()
一样,参数可以从右到左依次空着,空着的参数会被设为相应的当前 GMT 值。
zhong311 at collegeclub dot com
14-Feb-2004 07:40
When attempting to use HTTP's If-Modified-Since features for caching I ran
into the problem of being able to compare the GMT date the browser was
sending to my own Last-Modified date (stored in a database field). I saw
many examples of how to create a GMT date from a unix timestamp, but little
on how to actually get a GMT date into a unix timestamp. Perhaps someone
has a better way, here's my solution:
<?php
function
gmstrtotime($sgm) { $months = array( 'Jan'=>1,
'Feb'=>2, 'Mar'=>3, 'Apr'=>4,
'May'=>5, 'Jun'=>6, 'Jul'=>7,
'Aug'=>8, 'Sep'=>9, 'Oct'=>10,
'Nov'=>11, 'Dec'=>12 ); list($D, $d, $M, $Y,
$H, $i, $s) = sscanf($sgm, "%3s, %2d %3s %4d %2d:%2d:%2d
GMT"); return gmmktime($H, $i, $s, $months[$M], $d,
$Y); }
// test: after all is said and done // $time should be
the same as $gmtime
$time = time(); $us = date("m/d/Y
H:i:s",$time); $sgm = gmdate("D, d M Y H:i:s",$time) .
" GMT";
$gmtime = gmstrtotime($sgm);
echo $us .
" "; echo $sgm . " "; echo $time .
" "; echo $gmtime .
" ";
?>
My results:
02/13/2004
10:45:42 Fri, 13 Feb 2004 20:45:42
GMT 1076705142 1076705142
Credit to kyle at frozenonline dot
com for his strtotime example
| |