PHP implementation compatibility 2038 years after the Unix timestamp conversion function, 2038unix_php tutorial

Source: Internet
Author: User
Tags learn php

PHP implementation compatible with the UNIX timestamp conversion function after 2038 years, 2038unix


Use the same method as the old function.

Copy the Code code 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/969483.html www.bkjia.com true http://www.bkjia.com/PHPjc/969483.html techarticle The PHP implementation is compatible with the UNIX timestamp conversion function after 2038 years, and the 2038unix method is identical to the old function. Copy the code as follows: function Fun_strtotime ($var 1=0, $var 2=0) {if (! $var 2 ...

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