JRO*_*ROB 24 php timestamp date strtotime
我想在00:00:00获得该月第一天的时间戳.
例如,2012年1月1日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;
Run Code Online (Sandbox Code Playgroud)
这是返回当月当天的零小时,而不是月初.
有什么建议?
nic*_*ckb 23
试试这个:
echo date( 'F jS Y h:i:s A', strtotime( 'first day of ' . date( 'F Y')));
Run Code Online (Sandbox Code Playgroud)
这将输出:
June 1st 2012 12:00:00 AM
Run Code Online (Sandbox Code Playgroud)
ses*_*ser 14
试试这个
$time = strtotime(date('Y-m-01 00:00:00')); // == 1338534000
Run Code Online (Sandbox Code Playgroud)
这意味着:
$date = date('Y-m-d H:i:s', $time); // == 2012-06-01 00:00:00
Run Code Online (Sandbox Code Playgroud)
echo date("Y-m-d 00:00:00", strtotime("first day of this month"));
Run Code Online (Sandbox Code Playgroud)
这输出:
2017-05-01 00:00:00
Run Code Online (Sandbox Code Playgroud)