+316原创程序 +49收集论文 +84原创文章 +1669VIP客户 +3263101总访问量
您的位置:首页 > 设计师随笔 > excel导入到mysql时日期时间类型处理
excel导入到mysql时日期时间类型处理
作者/来源:原创    时间:2014-09-23    关注3608次

用php将excel表格导入到mysql数据库时,相信大家都会遇到,导入进去的时间和excel表格时间不一样。在这里,分享给大家一个函数,可以解决这个问题。


function exceltimtetophp($days){
   if(is_numeric($days)){
      $jd = GregorianToJD(1, 1, 1970);
      $shijian=($days-intval($days))*24*3600;//时间秒
      $shi=str_pad(intval($shijian/3600),2,'0',STR_PAD_LEFT);
      $fen=str_pad(intval(($shijian-$shi*3600)/60),2,'0',STR_PAD_LEFT);
      $miao=str_pad(intval($shijian-$shi*3600-$fen*60),2,'0',STR_PAD_LEFT);
      $gregorian = JDToGregorian($jd+intval($days)-25569);
      $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);
      return $myDateStr." $shi:$fen:$miao";
    }
   else{
$tempArr=explode("/",$days);
$new=$tempArr[2].'-'.$tempArr[1].'-'.$tempArr[0];
return date("Y-m-d",strtotime("-1 day",strtotime($new)));
    }
}

本函数经过实测,能完美解决此问题。


©专业辅导 php毕业设计,php课程设计,php期末作业,php大作业,品质保证 访问:3263101次  
9laile.com源码在线销售平台由本站设计师齐工独立研发
当前版本V1.1.18
皖ICP备05020966号

皖公网安备 34072202000111号

 68813382