我正在尝试创建一个简单的脚本,在日期命中时隐藏内容。
所以当它是03-11-2016时,显示内容但是当日期是03-15-2016时,隐藏内容。
if(date(m-d-Y) > "03-15-2016") {
// do stuff
}
可悲的是,下面的脚本因某些原因无法正常工作,任何帮助都会很好,谢谢!
答案 0 :(得分:1)
如果您希望保持与当前脚本相同的格式,则可以使用:
<?php
if(strtotime(date("Y-m-d")) > strtotime("2016-1-04")) {
// do stuff
}
?>
答案 1 :(得分:0)
考虑使用类似的东西:
$today = time(); // time() is now (timestamp) since epoch
$hideIt = strtotime("2016-03-15"); // timestamp of date to hide stuff
if ( $today > $hideIt ) // if today is greater than the date we want to hide things
{
// do stuff...
}
答案 2 :(得分:0)
date
函数返回一个字符串。比较字符串可能会导致一些意外的结果。您需要比较的是日期的时间戳:
if (strtotime("now") > strtotime("03/15/2016 00:00:00")) {
// do stuff
}
注意,我已将您的"03-15-2016"
更改为"03/15/2016"
格式,这可以通过strtotime
函数进行解析。
答案 3 :(得分:0)
您的语法无效,因为您使用的参数顺序错误。您需要先按年,月和日来按顺序使用它们:
function findObject(arr, target) {
for (let i = 0; i < arr.length; i++) {
for (let j = 0; j < arr[i].length; j++) {
if (arr[i][j].id === target.id)
arr[i][j] = target;
}
}
}
findObject(arr, target);
// do stuff with arr