Python's Archiver

為方便港臺同胞閱覽,Python中國特別推出簡繁體內容轉換功能

xieaotian 发表于 2008-10-16 20:56

PHP函数(日期) ==> mktime() 与 strtotime()

mktime() 函数
Definition and Usage
定义和用法
The mktime() function returns the Unix timestamp for a date.
mktime()函数的作用是:返回一个日期的Unix时间戳。

This timestamp contains the number of seconds between the Unix Epoch (January 1 1970 00:00:00 GMT) and the time specified.
这个时间戳包含了Unix Epoch (January 1 1970 00:00:00 GMT)和指定时间之间相隔的秒数。
[separator]



Syntax
语法
mktime(hour,minute,second,month,day,year,is_dst)
Parameter参数 Description描述
hour Optional. Specifies the hour
可选参数。指定小时
minute Optional. Specifies the minute
可选参数。指定分钟
second Optional. Specifies the second
可选参数。指定秒数
month Optional. Specifies the numerical month
可选参数。指定月份
day Optional. Specifies the day
可选参数。指定日
year Optional. Specifies the year. The valid range for year is on some systems between 1901 and 2038. However this limitation is overcome in PHP 5
可选参数。指定年份。在有些系统中,年份是基于1901年和2038年之间的。然而这些旨在PHP 5以上的版本中支持
is_dst Optional. Set this parameter to 1 if the time is during daylight savings time (DST), 0 if it is not, or -1 (the default) if it is unknown. If it's unknown, PHP tries to find out itself (which may cause unexpected results). Note: This parameter became deprecated in PHP 5. The new timezone handling features should be used instead.
可选参数。如果是夏令时[dst],则此参数为1;如不是则为0;如果不确定则为-1。如果是不确定的情况,那么PHP将会自行查找结果(这可能导致不可预想的结果)
注意:我们不提倡在PHP 5种使用该参数。我们应该使用别的方法来代替使用这种“新时区处理方法”

Tips and Notes
注意点
Note: If the arguments are invalid, the function returns false (PHP versions before 5.1 returns -1).
注意:如果自变量是无效的,函数返回False(如果是PHP5.1以前的版本则返回 -1)。

strtotime() 函数
Definition and Usage
定义和用法
The strtotime() function parses an English textual date or time into a Unix timestamp (the number of seconds since January 1 1970 00:00:00 GMT).
strtotime()函数的作用是:将任何英文文本的日期时间描述解析为Unix时间戳(从1970年1月1日(GMT)起经过的秒数)。

Syntax
语法
strtotime(time,now)


Parameter参数 Description描述
time Required. Specifies the time string to parse
必要参数。指定需要被解析的时间字符串。
now Optional. Specifies the timestamp used to calculate the returned value. If this parameter is omitted, current time is used
可选参数。指定用来计算返回值的时间戳。如果这个参数被忽略,那么将默认使用当前时间


--------------------------------------------------------------------------------

Tips and Notes
注意点
Note: If the year is specified in a two-digit format, values between 0-69 are mapped to 2000-2069 and values between 70-100 are mapped to 1970-2000.
注意:如果时间是以两位数字的格式指定的,那么数字“0-69”指的是2000-2069年,数字“70-100”指的是1970-2000年。

Note: In PHP 5.1.0 this function returns false on failure (earlier versions returns -1).
注意:在 PHP 5.1.0版本中,如果函数失效,它将返回false(早期版本将返回 -1)。



本次工作中使用它来得到一个时间差(days),并循环显示每天的相关记录
<code>
<?php
if(get('set') == 'show')
{
    $enddate = mktime(post('ehou'),"0","0",post('emon'),post('eday'),date("Y"));
    $startdate = mktime(post('shou'),"0","0",post('smon'),post('sday'),date("Y"));
    $days = round(($enddate-$startdate)/3600/24);

?>
    <table border="1">
        <tr>
            <td>日期</td><td>到达第一页面用户数</td><td>到达第二页面用户数</td>
        </tr>
        <?php
            //循环显示数据
            for($i==0;$i<$days;$i++)
            {
                $td1 = mktime(post('shou'),"0","0",post('smon'),post('sday')+$i,date("Y"));
                $td1 = date("Y-m-d",$td1);

                $td2 =  getUserNumsForPage1($td1);
                $td3 =  getUserNumsForPage2($td1);

        ?>
        <tr>
            <td align="center"><?php echo $td1;?>&nbsp;</td><td align="center"><?php echo $td2[0]['tot'];?>&nbsp;</td><td    align="center"><?php echo $td3[0]['tot'];?>&nbsp;</td>
        </tr>
        <?php

            }
        ?>
    </table>
<?php
}
?>
</code>

页: [1]

Powered by Discuz! Archiver 6.1.0  © 2001-2007 Comsenz Inc.