zoukankan      html  css  js  c++  java
  • php解决2038年后时间转化时间戳以及时间搓转化时间的问题,超级详细

    首先编写两个函数如下:

    /**
     * # +========================================================================
     * # | - @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');
  • 相关阅读:
    [Gamma阶段]展示博客
    [Gamma阶段]测试报告
    软工实践个人总结
    小组最终答辩
    第08组 Beta版本演示
    第08组 Beta冲刺(5/5)
    第08组 Beta冲刺(4/5)
    第08组 Beta冲刺(2/5)
    第08组 Beta冲刺(3/5)
    第08组 Beta冲刺(1/5)
  • 原文地址:https://www.cnblogs.com/leaf-cq/p/15118046.html
Copyright © 2011-2022 走看看