php实现兼容2038年后Unix时间戳转换函数,2038unix_PHP教程

WBOY
Release: 2016-07-13 10:02:58
Original
895 people have browsed it

php实现兼容2038年后Unix时间戳转换函数,2038unix

使用方法跟旧的函数一模一样.

复制代码 代码如下:
function fun_strtotime($var1=0,$var2=0){
    if(!$var2){
        $var2 = $var1;
        $var1 = 0;
    }
    if(is_numeric($var2)){
       $var2 = '@'.$var2;
    }
    try{
        $date  =  new DateTime($var2);
        $date->setTimezone(new DateTimeZone(date_default_timezone_get()));
    }catch(Exception $e){ $date = 0;}
    if(is_object($date)){
        if($var1)
            $date->modify($var1);
        return $date->format('U');
    }else{
        return 0;
    }
}
function fun_date($var1=0,$var2=0){
    if(!$var2){
        $var2 = $var1;
        $var1 = 'Y-m-d H:i:s';
    }
    try{
        $date  =  new DateTime('@'.$var2);
        $date->setTimezone(new DateTimeZone(date_default_timezone_get()));
    }catch(Exception $e){ $date = 0;}
    if(is_object($date)){
        return $date->format($var1);
    }else{
        return '';
    }
}

以上就是本文所述的全部内容了,希望对大家学习php有所帮助。

www.bkjia.comtruehttp://www.bkjia.com/PHPjc/969483.htmlTechArticlephp实现兼容2038年后Unix时间戳转换函数,2038unix 使用方法跟旧的函数一模一样. 复制代码 代码如下: function fun_strtotime($var1=0,$var2=0){ if(!$var2...
Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!