我正在尝试获取每月第一天 00:00:00 的时间戳。
例如,时间戳 Jan 01 2012 00:00:00
我正在这样做:
$test_month = time(); // Seconds
$test_month = date('M', $test_month); // This month
$test_month = strtotime($test_month); // Timestamp of this month
echo $test_month;
这是返回当月当天的零小时,而不是月初。
有什么建议吗?
试试这个:
echo date( 'F jS Y h:i:s A', strtotime( 'first day of ' . date( 'F Y')));
这将输出:
June 1st 2012 12:00:00 AM
试试这个
$time = strtotime(date('Y-m-01 00:00:00')); // == 1338534000
翻译过来就是:
$date = date('Y-m-d H:i:s', $time); // == 2012-06-01 00:00:00
阅读有关 date() 和 time() 函数的 PHP 手册。
echo date("Y-m-d 00:00:00", strtotime("first day of this month"));
这输出:
2017-05-01 00:00:00