當前位置:首頁 » 編程語言 » php1970

php1970

發布時間: 2025-04-23 07:30:36

『壹』 php 如何處理 1970前時間 時間戳失效了

php5.2+提供了DateTime類來處理這樣的問題,參考方案如下(請注意時區的處理):

//1、Unix時間戳轉日期functionunixtime_to_date($unixtime,$timezone='PRC'){$datetime=newDateTime("@$unixtime");//DateTime類的bug,加入@可以將Unix時間戳作為參數傳入$datetime->setTimezone(newDateTimeZone($timezone));return$datetime->format("Y-m-dH:i:s");}

//2、日期轉Unix時間戳
functiondate_to_unixtime($date,$timezone='PRC'){
$datetime=newDateTime($date,newDateTimeZone($timezone));
return$datetime->format('U');
}

echodate_to_unixtime("1900-1-3100:00:00");//輸出-2206425952
echo'<br>';
echounixtime_to_date(date_to_unixtime("1900-1-3100:00:00"));//輸出1900-01-3100:00:00

『貳』 php讀取mysql網頁顯示是1970-01-01 資料庫中是字元串類型,比如41036讀取出為日期為2012-05-07

一般時間都是用這樣方法存的,用date函數轉化就行了,<?php echo date('Y-m-d',資料庫數據);?>

熱點內容
25系列編程器 發布:2025-09-24 08:19:23 瀏覽:272
小米6換機熱點密碼是多少 發布:2025-09-24 08:08:00 瀏覽:24
c語言10的階乘 發布:2025-09-24 08:07:49 瀏覽:351
南寧少兒編程培訓 發布:2025-09-24 07:16:35 瀏覽:321
非易失存儲 發布:2025-09-24 06:59:14 瀏覽:491
安卓備用機哪裡買比較便宜 發布:2025-09-24 06:44:53 瀏覽:580
360壓縮解壓文件丟失 發布:2025-09-24 06:44:44 瀏覽:927
內網ip怎麼訪問內網伺服器地址 發布:2025-09-24 06:20:20 瀏覽:950
編譯安卓內核需要准備什麼 發布:2025-09-24 06:19:34 瀏覽:322
遞歸的Java 發布:2025-09-24 06:10:58 瀏覽:664