2016-04-19 186 views
0

我只想計算時間戳的午夜值。例如,1461043742這是今天的時間戳,我想從中獲得午夜12點鐘時間戳值的時間戳。而這是明天的時間戳1461130928,我希望明天午夜12點鐘的時間戳值顯示。我該如何做到這一點,有沒有可能在PHP中實現這一點?從特定時間戳獲取午夜時間戳值

回答

-1

可以使用的strtotime

$date = '2016-04-18 00:00:00'; 
$timestamp = strtotime($date); 

$date = date('Y-m-d 00:00:00'); 
$timestamp = strtotime($date); 
0

您需要的小時和分鐘更改爲午夜。

$date = new DateTime() // By default gets the current time 
$date.setTime(0,0,0) // Midnight hour 
$stamp = date.getTimestamp() 
0

您可以使用strtotime

// Input: 
$now = 1461043742; 

// Calculate: 
$midnight = strtotime("midnight", $now); 
$midnight_tomorrow = strtotime("midnight tomorrow", $now); 

// Test 
print(date('c', $midnight)); 
print(date('c', $midnight_tomorrow));