I am trying to get the timestamp of the first day of the month at 00:00:00.
我想在00:00:00获得该月第一天的时间戳。
For example, the timestamp of Jan 01 2012 00:00:00
例如,2012年1月1日00:00:00的时间戳
I'm doing this:
我这样做:
$test_month = time(); // Seconds
$test_month = date('M', $test_month); // This month
$test_month = strtotime($test_month); // Timestamp of this month
echo $test_month;
This is returning zero hour of the current day of the month, not the start of the month.
这是返回当月当天的零小时,而不是月初。
Any suggestions?
有什么建议么?
3 个解决方案
#1
21
Try this:
尝试这个:
echo date( 'F jS Y h:i:s A', strtotime( 'first day of ' . date( 'F Y')));
This will output:
这将输出:
June 1st 2012 12:00:00 AM
#2
#3
1
echo date("Y-m-d 00:00:00", strtotime("first day of this month"));
This outputs:
这输出:
2017-05-01 00:00:00
#1
21
Try this:
尝试这个:
echo date( 'F jS Y h:i:s A', strtotime( 'first day of ' . date( 'F Y')));
This will output:
这将输出:
June 1st 2012 12:00:00 AM
#2
14
Try this
尝试这个
$time = strtotime(date('Y-m-01 00:00:00')); // == 1338534000
Which translates to:
这意味着:
$date = date('Y-m-d H:i:s', $time); // == 2012-06-01 00:00:00
Read the PHP manual on the date() and time() functions.
阅读关于date()和time()函数的PHP手册。
#3
1
echo date("Y-m-d 00:00:00", strtotime("first day of this month"));
This outputs:
这输出:
2017-05-01 00:00:00