PHP implementation compatible with the UNIX timestamp conversion function after 2038 years
This article mainly introduces the PHP implementation compatibility 2038 years after the Unix timestamp conversion function, using the same method and the function, very practical, recommended to everyone, I hope you can like.
Use the same method as the old function.
The code is as follows:
function Fun_strtotime ($var 1=0, $var 2=0) {
if (! $var 2) {
$var 2 = $var 1;
$var 1 = 0;
}
if (Is_numeric ($var 2)) {
$var 2 = ' @ '. $var 2;
}
try{
$date = new DateTime ($var 2);
$date->settimezone (New Datetimezone (Date_default_timezone_get ()));
}catch (Exception $e) {$date = 0;}
if (Is_object ($date)) {
if ($var 1)
$date->modify ($var 1);
return $date->format (' U ');
}else{
return 0;
}
}
function Fun_date ($var 1=0, $var 2=0) {
if (! $var 2) {
$var 2 = $var 1;
$var 1 = ' y-m-d h:i:s ';
}
try{
$date = new DateTime (' @ '. $var 2);
$date->settimezone (New Datetimezone (Date_default_timezone_get ()));
}catch (Exception $e) {$date = 0;}
if (Is_object ($date)) {
return $date->format ($var 1);
}else{
Return ';
}
}
The above is the whole content of this article, I hope to learn PHP to help you.
http://www.bkjia.com/PHPjc/969963.html www.bkjia.com true http://www.bkjia.com/PHPjc/969963.html techarticle PHP implementation compatible with the UNIX timestamp conversion function after 2038 years this article mainly introduces the PHP implementation compatibility 2038 years after the Unix timestamp conversion function, using the same method as the function, very practical, ...