【问题标题】:PHP Date or TimeStamp Function to check time elapsed within the same day, same week, or more than a weekPHP Date 或 TimeStamp 函数检查同一天、同一周或一周以上的时间
【发布时间】:2012-06-10 20:57:38
【问题描述】:

对于 PHP,给出年份的函数。

   $date = date('n/j/Y', $time);
  echo $date; 

或表示为时间戳

   $time = strtotime($date);
   echo $time; 

基本上,我希望我的帖子列表在超过一周的时候显示月/日/年。 并列为星期一,星期二...一周中的一天,当帖子在一周内时。 而当发帖是在同一天之内,则表示几小时前或几分钟前。

是否需要使用时间戳进行减法才能查看经过的时间?它确实如何将其恢复为同一天或同一周内过去的时间?

谢谢

【问题讨论】:

    标签: php date time


    【解决方案1】:
    $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)";
    }
    

    【讨论】:

      猜你喜欢
      • 2019-05-30
      • 1970-01-01
      • 1970-01-01
      • 2012-01-24
      • 2018-02-04
      • 1970-01-01
      • 2019-11-11
      • 1970-01-01
      • 2015-08-24
      相关资源
      最近更新 更多