开发者

strtotime - a second before midnight

开发者 https://www.devze.com 2023-02-14 23:00 出处:网络
I attempted this: $date_string = strtotime(\'6 Mar, 2011 23:59:59\'); But I think PHP can\'t interpret that for some reason as it returned empty. I tried this:

I attempted this:

$date_string = strtotime('6 Mar, 2011 23:59:59');

But I think PHP can't interpret that for some reason as it returned empty. I tried this:

$date_string = strtotime('6 Mar, 2开发者_C百科011 midnight');

The above worked but I need it to be a second before midnight i.e. the last second of the day. How can I get strtotime to return this without changing the 6 Mar, 2011 part?


Hope this helps. I used this and it gives todays timestamp just before midnight. Counter intuitive.

$today_timestamp =  strtotime('tomorrow - 1 second');


It works for me if I use March 6, 2011 23:59:59. Any chance of changing the input format?

Other than that, you could of course subtract 1 second from the timestamp. Note however that you need to use March 7:

$date_string = strtotime('7 Mar, 2011 midnight') - 1;


Why not use mktime?

mktime(23,59,59,3,6,2011);


If you're on PHP 5.3 or greater, you could use the DateTime class.

The createFromFormat function allows you to manually specify how to parse your input date string.

$date = '6 Mar, 2011 23:59:59';
$timestamp = DateTime::createFromFormat('d M, Y H:i:s', $date)->getTimestamp();
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号