2010-12-01

[PHP] The DateTime Class

Doctrine 2 裡記錄時間都是用 PHP 的 DateTime Class
所以小研究一下

In PHP 5.2+

新增一個當前時間的 DateTime Class
$date = new DateTime("now");
ps. string "now" 可以不用打,預設就是 "now"

跟據 format 回傳 DateTime Class 的時間
echo $date->format('Y-m-d H:i:s');

參考資料:
http://www.php.net/manual/en/class.datetime.php

沒有留言 :

張貼留言