PHP implementation compatibility 2038 years after the Unix timestamp conversion function _php Tutorial

Source: Internet
Author: User

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, ...

  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.