Home >php教程 >php手册 >php 兼容2038年后时间转换函数.

php 兼容2038年后时间转换函数.

WBOY
WBOYOriginal
2016-06-06 19:35:371248browse

使用方法跟旧的函数一模一样.. PHP 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_

使用方法跟旧的函数一模一样.. 
PHP
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 '';
    }
}
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
Previous article:PHP获取和设置配置参数函数Next article:nginx url重写