1、從Excel檔中讀出之日期格式為格林威治時間。
2、實際應用需轉換成本地時間,例如:台北時間比格林威治時間快8小時(28800秒),需減去八小時(28800秒)。
¨ 範例
$file_path = "../upload/txtfile/monitor_value/"; //來源檔目錄路徑
$upfile = "test123.xls "; //Excel檔名
//擷取附檔名,判斷是Excel檔或CSV檔
$upfile_type = strtolower(pathinfo($upfile, PATHINFO_EXTENSION));
//Excel檔,將資料輸出為CSV檔
if($upfile_type == "xls"){
$xls_data = new Spreadsheet_Excel_Reader();
$xls_data->setOutputEncoding('Big5');
$xls_data->read($upfile);
error_reporting(E_ALL ^ E_NOTICE);
//匯出CSV檔案路徑檔名,檔名後加上目前時間
$csv_filename = $file_path."csv".date("YmdHis").".csv";
$fp = fopen ($csv_filename,"a");
for ($i = 1; $i <= $xls_data->sheets[0]['numRows']; $i++) {
for ($j = 1; $j <= $xls_data->sheets[0]['numCols']; $j++) {
$str = "\"".$xls_data->sheets[0]['cells'][$i][$j]."\"";
if($j < $xls_data->sheets[0]['numCols']){
$str .= ",";
}
fputs($fp,$str);
}
fputs($fp,"\r\n");
}
fclose ($fp);
}
//轉換成本地時間,date("Z") 目前時區與格林威治時間誤差秒數 "-43200 "~"43200 "
$timestamp_GMT = strtotime(trim($data[1])); //第二欄即為日期時間,目前資料為格林威治時間,轉成timestamp
$timestamp = $timestamp_GMT - date("Z"); //格林威治時間,需補上時差秒數
3、修改日期輸出格式
¨ 檔案:Spreadsheet_Excel_Reader\Excel\reader.php
¨ 日期輸出格式變數 $dateFormats
¨ 原來日期輸出格式為 “日/月/年”,改成”年/月/日”。
¨ 修改前
var $dateFormats = array (
0xe => "d/m/Y",
0xf => "d-M-Y",
0x10 => "d-M",
0x11 => "M-Y",
0x12 => "h:i a",
0x13 => "h:i:s a",
0x14 => "H:i",
0x15 => "H:i:s",
0x16 => "d/m/Y H:i",
0x2d => "i:s",
0x2e => "H:i:s",
0x2f => "i:s.S");*/
¨ 修改後
var $dateFormats = array (
0xe => "Y/m/d",
0xf => "Y-M-d",
0x10 => "M-d",
0x11 => "Y-M",
0x12 => "h:i a",
0x13 => "h:i:s a",
0x14 => "H:i",
0x15 => "H:i:s",
0x16 => "Y/m/d H:i",
0x2d => "i:s",
0x2e => "H:i:s",
0x2f => "i:s.S");
全站熱搜
留言列表