Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/date/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
PHP日期或时间戳函数,用于检查在同一天、同一周或一周以上经过的时间_Php_Date_Time - Fatal编程技术网

PHP日期或时间戳函数,用于检查在同一天、同一周或一周以上经过的时间

PHP日期或时间戳函数,用于检查在同一天、同一周或一周以上经过的时间,php,date,time,Php,Date,Time,对于PHP,提供年份日期的函数 $date = date('n/j/Y', $time); echo $date; 或者表示为时间戳 $time = strtotime($date); echo $time; 基本上,当我的帖子超过一周的时候,我想把它列为月/日/年。 并被列为星期一、星期二……一周中的某一天,在这一周内发布帖子。 当发帖时间在同一天内时,则表示多少小时前或多少分钟前 我是否需要使用时间戳进行减法以查看经过的时间?我该如何把它带回来,比如说,在同一天

对于PHP,提供年份日期的函数

   $date = date('n/j/Y', $time);
  echo $date; 
或者表示为时间戳

   $time = strtotime($date);
   echo $time; 
基本上,当我的帖子超过一周的时候,我想把它列为月/日/年。 并被列为星期一、星期二……一周中的某一天,在这一周内发布帖子。 当发帖时间在同一天内时,则表示多少小时前或多少分钟前

我是否需要使用时间戳进行减法以查看经过的时间?我该如何把它带回来,比如说,在同一天或同一周内,时间流逝了多少

thx

$currentTime=time();
如果($currentTime
$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)";
}