簡體   English   中英

從php文件中的數據庫分別獲取日期,月份年份的問題?

[英]problem to Get Date, month Year separately From database in Php File?

我想從數據庫中獲取日期,月份,時間,小時,分鍾,秒,秒,用於倒數計時器,在數據庫中存儲的日期為2010/10/10:我使用此代碼:

$m=date('m',$row['Date']);
$d=date('d',$row['Date']);

輸出是month = 31 date = 12 ...

如果您想分開使用它們,可以將explode功能與list一起使用,例如:

list($year, $month, $day) = explode('/', $row['Date']);

另外,您可以使用strtotime函數獲取單個值:

echo 'Day' . date('d', strtotime($row['Date']));
echo 'Month' . date('m', strtotime($row['Date']));
echo 'Year' . date('Y', strtotime($row['Date']));
$d = // Pull your date from the db
$date = new DateTime($d);

$day = $date->format('l'); // Creates day name
$day = $date->format('j')  // Creates date number
$month = $date->format('n'); // Creates month number
$year = $date->format('Y'); // Creates year

..依此類推。

您可以在這里http://php.net/manual/en/function.date.php找到格式設置選項

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM