当前位置: 代码迷 >> 综合 >> excel表格时间转为时间戳
  详细解决方案

excel表格时间转为时间戳

热度:26   发布时间:2024-02-20 23:05:23.0
/*** excel表格时间转为时间戳** @param string $excelTime excel表格时间* @param boolean $time     是否时间设为今天零点时间* @return string            日期格式*/public static function excelTimeToTime(string $excelTime, bool $time = false) : string{//如果是数字则转化,如果是有 - 或者 /,视作文本格式不作处理$type1 = strpos($excelTime, '/');$type2 = strpos($excelTime, '-');if($type1 || $type2) {$return_date = $excelTime;}else{if(function_exists('GregorianToJD')) {if (is_numeric( $excelTime )) {$jd          = GregorianToJD( 1, 1, 1970 );$gregorian   = JDToGregorian( $jd + intval ( $excelTime ) - 25569 );$date        = explode( '/', $gregorian );$return_date = str_pad( $date [2], 4, '0', STR_PAD_LEFT )."-". str_pad( $date [0], 2, '0', STR_PAD_LEFT )."-". str_pad( $date [1], 2, '0', STR_PAD_LEFT ). ($time ? " 8:00:00" : '');return $return_date;}} else {$excelTime   = $excelTime>25568?$excelTime:25569;$ofs         = (70 * 365 + 17+2) * 86400;$return_date = date("Y-m-d",($excelTime * 86400) - $ofs).($time ? " 8:00:00" : '');}}return $return_date;}

 

  相关解决方案