26

我试图在 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;

这是返回当月当天的零小时,而不是月初。

有什么建议么?

4

3 回答 3

24

试试这个:

echo date( 'F jS Y h:i:s A', strtotime( 'first day of ' . date( 'F Y')));

这将输出:

June 1st 2012 12:00:00 AM
于 2012-06-28T00:55:01.983 回答
16

试试这个

$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 手册。

于 2012-06-28T00:54:01.703 回答
5
echo date("Y-m-d 00:00:00", strtotime("first day of this month"));

这输出:

2017-05-01 00:00:00
于 2017-05-27T05:39:46.873 回答