[英]PHP Date or TimeStamp Function to check time elapsed within the same day, same week, or more than a week
對於PHP,提供年份日期的函數。
$date = date('n/j/Y', $time);
echo $date;
或表示為時間戳
$time = strtotime($date);
echo $time;
基本上我希望我的帖子列表月/日/年,當它超過一周。 並列為星期一,星期二...星期幾,這些帖子都在一周之內。 當發布在同一天內,然后表達多少小時或幾分鍾前。
我是否需要使用時間戳來進行減法以查看已過去的時間? 它是如何將它帶回到同一天或同一周內流逝的時間?
謝謝
$currentTime = time();
if ($currentTime < strtotime('1 year ago', $currentTime) {
echo "at least a year old";
} else if ($currentTime < strtotime('1 month ago', $currentTime) {
echo "at least a month old (but not a year)";
} else if ($currentTime < strtotime('1 week ago', $currentTime) {
echo "at least a week old (but not a month)";
} else if ($currentTime < strtotime('1 day ago', $currentTime) {
echo "at least a day old (but not a week)";
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.