time - 试着知道这个日期是今天/明天/某天前
问题描述
我想检查日期是今天、明天、昨天还是以前。但是我的代码不起作用。
代码:
public function istimedate($timestamp=''){
$timestamp=date_create($timestamp);
$date = strtotime(date($timestamp,"Y-m-d"));
$current_Time = strtotime(date("Y-m-d"));
if($date == $current_Time) {
$day_time = 'Today';
} elseif(strtotime("-1 day", $date) == $current_Time) {
$day_time = 'Yesterday';
} elseif(strtotime("+1 day", $date) == $current_Time) {
$day_time = 'Tomorrow';
} else {
$day_time = 'Someday ago';
}
return $day_time;
}
$day = $this->istimedate('2021-01-01 09:33:04');
解决方案
使用正确格式转换的日期。$date = strtotime(date_format($timestamp,"Y-m-d"));
安装的$date = strtotime(date($timestamp,"Y-m-d"));
推荐阅读
- javascript - forEach 循环将属性设置为 CSS 值
- java - Eclipse 可以在不更改底层代码的情况下呈现 Java 花括号吗?
- javascript - 我可以为 facebook 制作一个分享按钮并将其与特定的 div 链接以分享吗?
- ios - 选择另一个 UITableView 单元格时如何取消选择?
- jmeter - 如何使用 JMS Publisher 和 JMS Subscriber 在 JMeter 中为订阅者过滤来自 ActiveMQ 的响应消息
- prolog - 如何在序言规则中接受 k 项?
- xcode - 在 macOS 上针对多个架构自定义每个切片编译器标志
- dc.js - 使用交叉过滤器(dc.js)的维度中的唯一值计数
- python - Python:打开多个 ActiveX 框架时出现参数错误
- javascript - 在 Safari iOS 上使用下拉手势防止从全屏退出