首页 > Web开发 > 详细

php解决2038年后时间转化时间戳以及时间搓转化时间的问题,超级详细

时间:2021-08-09 14:12:37      阅读:44      评论:0      收藏:0      [点我收藏+]

首先编写两个函数如下:

/**
 * # +========================================================================
 * # | - @NodeAnotation(title="时间戳转化时间")
 * # | - @author     cq <just_leaf@foxmail.com> 
 * # | - @copyright zmtek 2021-08-09
 * # +------------------------------------------------------------------------
 * # | - 1.此函数相当于date(),用法一样
 * # +========================================================================
 */
function systemdate($curformat, $utc_value) {
    
    while(1) {
        if($utc_value > 2147483647) {
            
            if(@date(‘Y‘, $utc_value) < 2038) {
                $mydate2 = new DateTime(‘@‘.$utc_value);
                $string = $mydate2->format($curformat);
                break;
            }
        }

        $string = date($curformat, $utc_value);
        break;
    }

    return $string;
}

/**
 * # +========================================================================
 * # | - @NodeAnotation(title="时间转化时间戳")
 * # | - @author     cq <just_leaf@foxmail.com> 
 * # | - @copyright zmtek 2021-08-09
 * # +------------------------------------------------------------------------
 * # | - 1.此函数相当于strtotime(),用法一样
 * # +========================================================================
 */
function systemstrtotime($str_time){
    
    $result = strtotime($str_time);
    if(empty($result)){
        $date = new DateTime($str_time);
        $result = $date->format(‘U‘);
    }
    return $result;
}

然后开始调用就可以了

# 时间搓转换日期
echo systemdate(‘Y-m-d‘,4782079738);
# 日期转换时间搓
echo systemstrtotime(‘2100-01-01‘);

 

php解决2038年后时间转化时间戳以及时间搓转化时间的问题,超级详细

原文:https://www.cnblogs.com/leaf-cq/p/15118046.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!