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;
}

PHP phpexcel 导入时间/日期转换时间戳的更多相关文章

  1. 时间日期转换工具类,获取当前时间YYYYMMDD24HHMISS、YYYYMMDDHHMISS

    YYYYMMDD24HHMISS:24小时制时间(显示上只是比YYYYMMDDHHMISS中间多了一个24),例:2018102224112440 YYYYMMDDHHMISS:12小时制时间,例20 ...

  2. js 时间日期与时间戳之间转换

    1 1.将时间(2017-08-10)转换时间戳 2 var startTime = '2017-08-10'; 3 var startdate = new Date(Date.parse(start ...

  3. 【MySQL笔记】字符串、时间日期转换

    1.新增一列,将字符串日期(年.月.日)转换为Date类型   报错:Error Code: 1175. You are using safe update:http://jingyan.baidu. ...

  4. Springmvc配置时间日期转换

    1.局部日期转换 @Controller public class ProductController{ @RequestMapping(value="/test/springmvc.do& ...

  5. python 有关datetime时间日期 以及时间戳转换

    直接上代码 其中有注释 #coding=utf-8 import time import datetime def yes_time(): #获取当前时间 now_time = datetime.da ...

  6. IOS 时间字符串转换时间戳失败问题

    链接:https://pan.baidu.com/s/1nw6VWoD 密码:1peh 有时候获取到的时间带有毫秒数或者是(2018-2-6 11:11:11)格式的(别说你没遇到过,也别什么都让后台 ...

  7. 02基于注解开发SpringMVC项目(jar包,异步,request,参数传递,多选的接收,Model传参,map传参,model传参,ajax,重定向,时间日期转换)

     1 所需jar包 项目结构如下: 2 web.xml配置文件的内容如下: <?xmlversion="1.0"encoding="UTF-8"?&g ...

  8. js时间日期转时间戳

    var contractstarttimea='2016-01-01'; var contractendtimea='2016-05-01'; var contractstart = Date.par ...

  9. python 使用time / datetime进行时间、时间戳、日期转换

    python 使用time 进行时间.时间戳.日期格式转换 #!/usr/bin/python3 # -*- coding: utf-8 -*- # @Time : 2017/11/7 15:53 # ...

随机推荐

  1. python---基础知识回顾(九)图形用户界面-------WxPython

    主要使用wxPython(最成熟的跨平台python GUI工具包) wxPython手册 前戏:基础了解 import wx class MyFrame(wx.Frame): #创建自定义Frame ...

  2. pandas基础整理

    用jupyter写好,直接放到GitHub上面了→_→ 博客链接:https://douzujun.github.io/page/%E6%95%B0%E6%8D%AE%E6%8C%96%E6%8E%9 ...

  3. NGINX配置详解及应用

    目录 NGINX    1 1.1    目录结构    1 1.2    基础配置    1 1.3    location    5 1.4    虚拟主机    5 1.5    状态模块    ...

  4. How to Tell Science Stories with Maps

    Reported Features How to Tell Science Stories with Maps August 25, 2015   Greg Miller This map, part ...

  5. 20155234 2016-2017-2 《Java程序设计》第6周学习总结

    20155234 2016-2017-2 <Java程序设计>第6周学习总结 教材学习内容总结 Java将输入/输出抽象化为串流,数据有来源及目的地,衔接两者的是串流对象. 从应用程序角度 ...

  6. Shell-修改MySQL默认root密码

    Code: mysqltmppwd=`cat /tmp/.mysql_secret | cut -b 87-102` mysqladmin -u root -p${mysqltmppwd} passw ...

  7. linux中core dump开启使用教程【转】

    转自:http://www.111cn.net/sys/linux/67291.htm 一.什么是coredump 我们经常听到大家说到程序core掉了,需要定位解决,这里说的大部分是指对应程序由于各 ...

  8. aarch64_fc26_url

    http://linux.yz.yamagata-u.ac.jp/pub/linux/fedora-projects/fedora-secondary/releases/26/Everything/a ...

  9. Codeforces Round #505

    Codeforces Round #505 A. Doggo Recoloring 题目描述:给定一个字符串,每次选择一个在字符串里面出现至少两次的字符,然后将这种字符变成那一种指定的字符,问最终这个 ...

  10. 通过`__slots__` 节省RAM

    标签(空格分隔): Python进阶 python中,由于创建每个实例都会有成员,这些成员都会被保存在dict中,但是Python不能静态分配RAM,当创建实例时,因此dict的大小会比所需要的内存大 ...