繁体   English   中英

如何获取当月,第一天,零小时的时间戳

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

我想在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;

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

有什么建议么?

尝试这个:

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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