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');
  • 相关阅读:
    Codeforces Round #443 Div. 1
    linux中ps命令
    占cpu 100%的脚本
    检查Linux系统cpu--内存---磁盘的脚本
    jQuery对象的属性操作
    关于js的一些收集
    Linux命令集合
    使用python操作excel表格
    Linux7.3系统 升级python到3.6使用ping主机脚本
    一个别人的线程池的编写
  • 原文地址:https://www.cnblogs.com/leaf-cq/p/15118046.html
Copyright © 2011-2022 走看看