码迷,mamicode.com
首页 > Web开发 > 详细

php读取excel时间42930转化为时间然后正则验证时间是否通过

时间:2017-07-19 14:05:53      阅读:187      评论:0      收藏:0      [点我收藏+]

标签:nbsp   mat   test   image   int   top   运用   return   png   

excel时间

技术分享

function exceltimtetophp($days,$time=false)
{
if(is_numeric($days))
{

//凯撒日计数,要把我们运用的从1970年开始的日期运用函数GregorianToJD(),转换为凯撒日计数
$jd = GregorianToJD(1, 1, 1970);  
$gregorian = JDToGregorian($jd+intval($days)-25569);
$gregorian = strtotime($gregorian);
$gregorian = date("Y/m/d",$gregorian);
// $myDate = explode(‘\\‘,$gregorian);
// $myDateStr = str_pad($myDate[2],4,‘0‘, STR_PAD_LEFT)."-".str_pad($myDate[0],2,‘0‘,STR_PAD_LEFT)."-".str_pad($myDate[1],2,‘0‘, STR_PAD_LEFT).($time?"00:00:00":‘\\‘);
return $gregorian;
}
return $time;
}

$val = ‘42930‘; //excel读取的内容
$val = exceltimtetophp($val);
$preg_date = ‘/^(\d{4})\/(0\d{1}|[1-9]{1}||1[0-2])\/(0\d{1}|[1-9]{1}|[12]\d{1}|3[01])$/‘; //正则验证时间:当时间为 2017/01/01或2017/1/1或2017/11/11这种的都通过
$status_date = trim($val);
echo $status_date;
preg_match($preg_date,$status_date,$matches);

var_dump($matches);

 结果如下:

技术分享

 

php读取excel时间42930转化为时间然后正则验证时间是否通过

标签:nbsp   mat   test   image   int   top   运用   return   png   

原文地址:http://www.cnblogs.com/chaihy/p/7204986.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!