0

PHPの場合、年の日付を与える関数。

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

またはタイムスタンプとして表現する

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

基本的に、1週間以上経過したときに、投稿リストを月/日/年にしたいです。投稿が週内にある月曜日、火曜日...曜日としてリストされます。また、投稿が同じ日以内の場合は、何時間前または何分前かを表現します。

経過時間を確認するために減算を行うためにタイムスタンプを使用する必要がありますか?そして、同じ日または同じ週の経過時間など、どのように元に戻すことができますか?

どうも

4

1 に答える 1

2
$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)";
}
于 2012-06-10T21:04:07.587 に答える