简体   繁体   中英

How to get timestamp of current month, first day of month, zero hour

I am trying to get the timestamp of the first day of the month at 00:00:00.

For example, the timestamp of Jan 01 2012 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?

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

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.

echo date("Y-m-d 00:00:00", strtotime("first day of this month"));

这输出:

2017-05-01 00:00:00

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM