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.