Php is compatible with the Unix timestamp conversion function _ php instance after January 1, 2038

Source: Internet
Author: User
This article mainly introduces how to implement the Unix timestamp conversion function compatible with php after January 1, 2038. the method of use is the same as that of the function. it is very practical and recommended to everyone. I hope you will like it. The usage is exactly the same as that of 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 help you learn php.

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.