我想我可能在strtotime()函数中发现了一个bug。
我的应用程序使用unix时间戳来设置特定日期的事件。我与这些时间戳一起使用相对时间格式字符串。
我编写了这个最小的代码来重现这个bug:
<?php
echo "Last day of " . date('M-Y', 1677628800) . " is: " . date('M-d-Y', strtotime('last day this month', 1677628800)) . " expecting march 31! <br
我刚刚注意到PHP函数的行为很奇怪,有人能解释我做错了什么吗?
下面的代码显示相同的结果
<?php
echo date('Y-m-t');
// Outputs last day of this month: 2016-03-31
echo date('Y-m-t', strtotime("-1 month"));
// For some reason outputs the same: 2016-03-31
echo date('Y-m-t', strtotime("+1 month"));
// Out
我想在foreach循环中显示两个日期之间的日期。假设日期从2014年5月1日开始,到2014年5月3日结束,.I想要这样显示
//仅使用for循环,这将显示我想要的结果
for($i=$dateFrom;$i<=$dateTo;$i++) {
echo $i."<br>";
}
May 1,2014
May 2, 2014
May 3, 2014
但是,当使用foreach循环显示它是模板时,此代码会返回。
May 3,2014
May 3, 2014
May 3, 2014
这是我在action.php中的代码
$dateTo = $r->get
我成功地将其简化为一个小脚本来复制这个问题(在两台不同的PC上试过,但都使用了5.3.6):
<?php
$item = array('monthly_on_the' => 4);
$date = new DateTime();
$date->modify('first day of this month');
print_r($date);
$interval = new DateInterval('P'.$item['monthly_on_the'].'D');
print_r($interv
根据服务器: $ date
Wed Mar 1 01:46:06 EST 2017 php.ini date.timezone = America/New_York 当我这样做的时候,我得到了一个奇怪的结果: $month = date('M',strtotime('last day last month'));
$sel = "SELECT records where month='".$month."'";
echo $sel; 结果是: SELECT records where month