這是使用DateTime獲取PHP中當前時間的正確方法嗎?DateTime中的當前時間PHP
$currenttime = new DateTime();
$currenttime2 = $currenttime->format('H:i:s');
這是使用DateTime獲取PHP中當前時間的正確方法嗎?DateTime中的當前時間PHP
$currenttime = new DateTime();
$currenttime2 = $currenttime->format('H:i:s');
這將設置基於在php.ini的日期時間設置的時間。在創建後執行$ currenttime的var_dump以查看我的意思。你也可以使用microtime(true);獲取可以使用其他函數轉換的unix時間戳。
恩,你試過嗎?它看起來正確嗎? –
你可能想用'date_default_timezone_set(「America/New York」);'或者你的時區是什麼來作爲它的前綴。除此之外它應該沒問題。 http://php.net/manual/en/function.date-default-timezone-set.php –
是它正確的方式,'新的DateTime();' – 2013-08-07 19:22:35