0

强文本 包括“PHPExcel/IOFactory.php”;

// This is the file path to be uploaded.
$inputFileName = 'admin/' . $_SESSION['file_name'];

try {
    $objPHPExcel = PHPExcel_IOFactory::load($inputFileName);
} catch (Exception $e) {
    die('Error loading file "' . pathinfo($inputFileName, PATHINFO_BASENAME) . '": ' . $e->getMessage());
}

$allDataInSheet = $objPHPExcel->getActiveSheet()->toArray(null, true, true, true);

把日期放在excel表格中8/28/1980,但是我得到了这样的日期08-28-80,我需要得到这样的值1980-08-28

请帮我 !!

4

2 回答 2

0

如果您的日期是这样的 08-28-80,您将面临一个问题。如果您知道我的意思,您将无法确定年份是 1980 年还是 2080 年。

你可以使用这个功能

function convert_date($data){
    $date_arr = explode("-",$data);
    if($date_arr[2] >= 0 && $date_arr[2] < 17){
        $new_date = "20".$date_arr[2]."-".$date_arr[1]."-".$date_arr[0];
    } else {
        $new_date = "19".$date_arr[2]."-".$date_arr[1]."-".$date_arr[0];
    }
    return $new_date;
}

希望这个功能对你有帮助

于 2016-05-24T10:19:25.610 回答
-2

我希望这是你的期望。

请将excel日期值转换为字符串,

<?php
$dateVal = '8/28/1980'; // Excel date value
$date = strtotime($dateVal);
$newformat = date('Y-m-d',$date);
echo $newformat;
?>
于 2016-05-24T10:24:39.587 回答