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;
}
PHP phpexcel 导入时间/日期转换时间戳的更多相关文章
- 时间日期转换工具类,获取当前时间YYYYMMDD24HHMISS、YYYYMMDDHHMISS
YYYYMMDD24HHMISS:24小时制时间(显示上只是比YYYYMMDDHHMISS中间多了一个24),例:2018102224112440 YYYYMMDDHHMISS:12小时制时间,例20 ...
- js 时间日期与时间戳之间转换
1 1.将时间(2017-08-10)转换时间戳 2 var startTime = '2017-08-10'; 3 var startdate = new Date(Date.parse(start ...
- 【MySQL笔记】字符串、时间日期转换
1.新增一列,将字符串日期(年.月.日)转换为Date类型 报错:Error Code: 1175. You are using safe update:http://jingyan.baidu. ...
- Springmvc配置时间日期转换
1.局部日期转换 @Controller public class ProductController{ @RequestMapping(value="/test/springmvc.do& ...
- python 有关datetime时间日期 以及时间戳转换
直接上代码 其中有注释 #coding=utf-8 import time import datetime def yes_time(): #获取当前时间 now_time = datetime.da ...
- IOS 时间字符串转换时间戳失败问题
链接:https://pan.baidu.com/s/1nw6VWoD 密码:1peh 有时候获取到的时间带有毫秒数或者是(2018-2-6 11:11:11)格式的(别说你没遇到过,也别什么都让后台 ...
- 02基于注解开发SpringMVC项目(jar包,异步,request,参数传递,多选的接收,Model传参,map传参,model传参,ajax,重定向,时间日期转换)
1 所需jar包 项目结构如下: 2 web.xml配置文件的内容如下: <?xmlversion="1.0"encoding="UTF-8"?&g ...
- js时间日期转时间戳
var contractstarttimea='2016-01-01'; var contractendtimea='2016-05-01'; var contractstart = Date.par ...
- python 使用time / datetime进行时间、时间戳、日期转换
python 使用time 进行时间.时间戳.日期格式转换 #!/usr/bin/python3 # -*- coding: utf-8 -*- # @Time : 2017/11/7 15:53 # ...
随机推荐
- nandflash,norflash,sdram,emmc,rom,ram等各种存储器识别
老是被nandflash,norflash,sdram,emmc,rom,ram搞混,所以在这里总结一下,也为了更好的分清他们之间的关系,以至于别人问的时候不至于说不清. 我们不谈这些名次的由来,只说 ...
- 翻译: 星球生成 I
翻译: 星球生成 I 本文翻译自Planet Generation - Part I 译者: FreeBlues 以下为译文: 概述 我一直是一个过程内容生成的爱好者, 它允许你创建一个甚至不断改变的 ...
- 蓝桥杯 算法提高 3000米排名预测 DFS 递归搜索 next_permutation()使用
#include <iostream> #include <algorithm> #include <queue> #include <cstring> ...
- 关于mysql 5.7版本“报[Err] 1093 - You can't specify target table 'XXX' for update in FROM clause”错误的bug
不同于oracle和sqlserver,mysql并不支持在更新某个表的数据时又查询了它,而查询的数据又做了更新的条件,因此我们需要使用如下的语句绕过: , notice_code ) a) ; 本地 ...
- Spring容器事件、自定义事件
Spring容器内置事件,如容器的启动.停止.关闭.销毁等事件 <bean name="contextStartedHandler" class="com.nuts ...
- ASP.net--全局程序文件:Global.asax
ASP.NET应用程序只能有一个Global.asax文件,该文件支持许多项. •Application_Start:在应用程序接收到第一个请求时调用,这是在应用程序中给应用程序级的变量赋值或指定对所 ...
- phpcms 仿站小结
1.title<title>{if isset($SEO['title']) && !empty($SEO['title'])}{$SEO['title']}{/if}{$ ...
- 【leetcode 简单】 第九十五题 数字转换为十六进制数
给定一个整数,编写一个算法将这个数转换为十六进制数.对于负整数,我们通常使用 补码运算 方法. 注意: 十六进制中所有字母(a-f)都必须是小写. 十六进制字符串中不能包含多余的前导零.如果要转化的数 ...
- 2016.6.24——vector<vector<int>>【Binary Tree Level Order Traversal】
Binary Tree Level Order Traversal 本题收获: 1.vector<vector<int>>的用法 vector<vector<int ...
- gradle 构建工具,与Ant Maven关系
1 基本概念 gradle是一个基于Apache ant 和apache maven概念的项目自动化建构工具.它使用一种基于Groovy的特定领域语言来声明项目设置,而不是传统的xml.当前其支持 ...