PHP implementation is compatible with Unix timestamp conversion function after 2038, 2038unix_PHP tutorial

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

The PHP implementation is compatible with the Unix timestamp conversion function after 2038. The usage method of 2038unix

is exactly the same as the old function.

Copy code The code is as follows:
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 '';
}
}

The above is all the content described in this article. I hope it will be helpful to everyone learning php.

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/969483.htmlTechArticlephp implementation is compatible with the Unix timestamp conversion function after 2038. The usage method in 2038unix is ​​exactly the same as the old function. Copy code code As follows: 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