php讀取excel時間42930轉化為時間然後正則驗證時間是否通過

來源:互聯網
上載者:User

標籤: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轉化為時間然後正則驗證時間是否通過

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.