Home >Backend Development >PHP Tutorial >PHP implementation compatible with Unix timestamp conversion function after 2038_PHP tutorial

PHP implementation compatible with Unix timestamp conversion function after 2038_PHP tutorial

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOriginal
2016-07-13 10:02:44975browse

php implements timestamp conversion function compatible with Unix after 2038

This article mainly introduces PHP’s implementation of timestamp conversion function compatible with Unix after 2038, how to use it, and the functions Same, very practical, recommended to everyone, hope everyone likes it.

The usage method is exactly the same as the old function.

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/969963.htmlTechArticlephp realizes compatibility with Unix timestamp conversion function after 2038. This article mainly introduces php to realize compatibility with Unix after 2038. The timestamp conversion function is used in the same way as the previous function. It is very practical...
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