Home >php教程 >php手册 >PHP 时间和日期_PHP教程_编程技术

PHP 时间和日期_PHP教程_编程技术

WBOY
WBOYOriginal
2016-06-20 12:33:051155browse

<?php
    header("Content-type: text/html; charset=utf-8"); 
    date_default_timezone_set("PRC");
    //PHP提供了内置函数time()来取得服务器当前时间的时间戳。
    $curtime = time();
    echo $curtime;
    echo "<hr/>";
 
    //date() 函数用于格式化时间,返回一个字符串
    $date= date("Y-m-d H:i",$curtime);
    echo $date;
    echo "<hr/>";
 
    //mktime() 函数用于从日期取得时间戳,成功返回时间戳,否则返回 FALSE 
    // mktime(时, 分, 秒, 月, 日, 年)
    $mktime = mktime("21","50","18","12","30","2015");
    echo $mktime;
    echo "<hr/>";
 
    $datetime=date("Y-m-d H:i",$mktime);
    echo $datetime;
    echo "<hr/>";
    //strtotime() 函数用于将英文文本字符串表示的日期转换为时间戳
    $strtime = "2015-10-11 12:10";
    $timestr = strtotime("$strtime");
    echo $timestr;
    echo "<hr/>";
 
    echo date("Y-m-d H:i",$timestr);
 
    echo "<hr/>";
     
    //要求用户在登陆网站在2小时后失效而需要重新登录的例子
    $expiration = time()+2*3600;//得到当前时间延迟2小时候的时间戳
    echo $expiration;
?>



Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn