zoukankan      html  css  js  c++  java
  • PHP phpexcel 导入时间/日期转换时间戳

    strtotime(gmdate('Y-m-d H:i',PHPExcel_Shared_Date::ExcelToPHP($importtime)));

    /**
     * 判断字符串是否是日期格式
     * @param $date
     * @param $format
     * @return bool
     */
    function is_date($date, $format = 'Y-m-d')
    {
      if (!$date || $date == '0000-00-00') return false;
      $unix_time_1 = strtotime($date);
      if (!is_numeric($unix_time_1)) return false; //非数字格式
      $format_date = date($format, $unix_time_1);
      $unix_time_2 = strtotime($format_date);
      return ($unix_time_1 == $unix_time_2);
    }
    
    /**
     * excel数据导入  日期格式化
     * @param $date
     * @return false|string
     */
    function get_date_by_excel($date)
    {
      if (!$date || $date == '0000-00-00') return null;
    
      $unix_time = PHPExcel_Shared_Date::ExcelToPHP($date);
    
      return ($unix_time < 0) ? date('Y-m-d', $unix_time) : date('Y-m-d', strtotime(gmdate('Y-m-d', $unix_time)));
    }
    
    /**
     * 获取excel日期格式化结果
     * @param $date string excel日期单元格字符串
     * @param $default string  $date未非日期时返回默认日期
     * @return string
     */
    function excel_date_format($date, $default = '')
    {
      if ($default == '') $default = date('Y-m-d');
    
      if (is_date($date)) return $date;
    
      return get_date_by_excel($date) ?: $default;
    }
  • 相关阅读:
    Linux查看物理CPU个数、核数、逻辑CPU个数
    【完结】利用 Composer 完善自己的 PHP 框架(三)——Redis 缓存
    端口被占用
    选择器
    Css四种样式
    PT与PX,em(%)区别
    tomcat报404
    webservice调用接口,接口返回数组类型
    音频与视频标签
    表单标签2
  • 原文地址:https://www.cnblogs.com/PHPcoder404/p/9602618.html
Copyright © 2011-2022 走看看