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

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})/(0d{1}|[1-9]{1}||1[0-2])/(0d{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);

 结果如下:

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