laravel-excel的導(dǎo)入及時(shí)間格式導(dǎo)入mysql的問題

問題:原時(shí)間為2018-09-20但導(dǎo)入就變成了09-20-18

? ? use Excel;

? ? public function import(Request $request){

? ? ? ? ini_set('memory_limit','256M');

? ? ? ? if($request -> hasFile('excel') && $request -> file('excel') ->isValid()){

? ? ? ? ? ? size = $request -> file('excel') -> getSize();

? ? ? ? ? ? if($size > 2*1024*1024){

? ? ? ? ? ? ? ? $this -> setReturnInfo(-1,'請限制文件在2M之內(nèi)',[]);

? ? ? ? ? ? }


? ? ? ? ? ? $ext = $request -> file('excel') -> getClientOriginalExtension();? ?

? ? ? ? ? ? $realPath = $request -> file('excel') -> getRealPath();//臨時(shí)文件的絕對路徑

? ? ? ? ? ? // 上傳文件

? ? ? ? ? ? $filename = date('Y-m-d-H-i-s') . '-' . uniqid() . '.' . $ext;

? ? ? ? ? ? $bool = Storage::disk('local') -> put($filename, file_get_contents($realPath));

? ? ? ? ? ? if($bool == true){

? ? ? ? ? ? ? ? $filePath = 'storage/app/' . $filename;

? ? ? ? ? ? ? ? $data = [];

? ? ? ? ? ? ? ? $data = Excel::load($files, function($reader) use( &$res ) {?

? ? ? ? ? ? ? ? ? ? $reader = $reader->getSheet(0);?

? ? ? ? ? ? ? ? ? ? $res = $reader->toArray();?

? ? ? ? ? ? ? ? });

? ? ? ? ? ? ? ? foreach ($data as $key => $row) {//從第三行開始導(dǎo)入

? ? ? ? ? ? ? ? if($key == '0' || $key == '1'){

? ? ? ? ? ? ? ? continue;

? ? ? ? ? ? ? ? }

? ? ? ? ? ? ? ? $arr = [];

? ? ? ? ? ? ? ? $arr['entry_date'] = $row[0];//這樣導(dǎo)入的數(shù)據(jù)有問題

? ? ? ? ? ? ? ? $arr['creat_date'] = $row[001];


? ? ? ? ? ? ? ? DB::table('xxxx') -> insert([//這樣導(dǎo)入到數(shù)據(jù)庫為0000-00-00(字段胡默認(rèn)值)

? ? ? ? ? ? ? ? ? ? 'entry_date' => $arr['entry_date'],

? ? ? ? ? ? ? ? ? ? 'creat_date' => $arr['creat_date']

? ? ? ? ? ? ? ? ]);

? ? ? ? ? ? }


? ? ? ? }

? ? }

解決:打印出在excel中獲取的數(shù)據(jù)發(fā)現(xiàn),原來是2018-09-20,獲取到的是09-20-18

? ? 將獲取的時(shí)間數(shù)據(jù)按'-'分割成數(shù)組,在組合成時(shí)間就可以了

? ? if($row[0]!=""){

? ? ? ? ? ? $entry_date=explode("-",$row[10]);

? ? ? ? ? ? $arr['entry_date']=date("Y-m-d",mktime(0,0,0,$entry_date[0],$entry_date[1],$entry_date[2]));

? ? ? ? }else{

? ? ? ? ? ? $arr['entry_date'] = '0000-00-00';

? ? ? ? }

?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

  • pyspark.sql模塊 模塊上下文 Spark SQL和DataFrames的重要類: pyspark.sql...
    mpro閱讀 9,911評論 0 13
  • 1. Java基礎(chǔ)部分 基礎(chǔ)部分的順序:基本語法,類相關(guān)的語法,內(nèi)部類的語法,繼承相關(guān)的語法,異常的語法,線程的語...
    子非魚_t_閱讀 34,643評論 18 399
  • 最近特別喜歡寫大標(biāo)題,想利用這次學(xué)習(xí)寫作的機(jī)會整理整理自己的一些看法。在整理鞏固的基礎(chǔ)上,再找到自己的興趣,找到下...
    多多_7815閱讀 357評論 0 2
  • 遠(yuǎn)方的流云還在天空流浪 夕陽掛在城外的那棵老樹上 被涼涼的晚風(fēng)吹落山頭 烏鴉的嗚咽聲 隱沒在黃昏的最后一道光里 城...
    柳霧閱讀 236評論 0 1
  • 北京時(shí)間2月27日上午(美國時(shí)間2月26日晚),第89屆美國奧斯卡金像獎(jiǎng)?lì)C獎(jiǎng)禮在洛杉磯舉行,眾多電影人出席頒獎(jiǎng)禮。...
    華哥錄閱讀 347評論 0 0

友情鏈接更多精彩內(nèi)容