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
Release: 2016-07-13 10:02:44
Original
947 people have browsed it

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...
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
Latest Issues
php data acquisition?
From 1970-01-01 08:00:00
0
0
0
PHP extension intl
From 1970-01-01 08:00:00
0
0
0
How to learn php well
From 1970-01-01 08:00:00
0
0
0
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template