Typecho 类似微博上几分钟前、几天前

typecho教程 2020-08-25

  这样可以实现,在functions.php里添加如下代码:

  function getDayAgo($date){

  $d = new Typecho_Date(Typecho_Date::gmtTime());

  $now = $d->format(‘Y-m-d H:i:s’);

  $t = strtotime($now) – strtotime($date);

  if($t

  return $t . ‘秒前’;

  }

  if($t

  return floor($t / 60) . ‘分钟前’;

  }

  if($t

  return floor($t / 3670) . ‘小时前’;

  }

  if($t

  return floor($t / 86400) . ‘天前’;

  }

  if($t

  return floor($t / 604800) . ‘周前’;

  }

  if($t

  return floor($t / 2592000 ).’月前’;

  }

  return floor($t / 31536000 ).’年前’;

  }

  调用方法不变,比如在post.php调用文章发布时间:

  date(‘Y-m-d H:i’); ?>

  by muchun @ typecho论坛

评论 (0)
    Top