检查日期是过去还是将来

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了检查日期是过去还是将来相关的知识,希望对你有一定的参考价值。

Examine a date and return false if it's in the past, or true for the future.

Slightly more complicated than it needs to be, however there's an easy tutorial with full explanation if you follow the attached link.
  1. function checkDateAndTime($day,$month,$year,$hour,$minute) {
  2. $dateForConverting = $day."-".$month."-".$year."@".$hour.":".$minute;
  3. $formattedDate = date_create_from_format("[email protected]:i", $dateForConverting);
  4. $newDate = date_format($formattedDate, "Y-m-d H:i:s");
  5. $now = date("Y-m-d H:i:s", time());
  6. $newDateInSecs = strtotime($newDate);
  7. $nowInSecs = strtotime($now);
  8. $returnBool = true;
  9. $diffInSecs = $newDateInSecs - $nowInSecs;
  10. if($diffInSecs < 0) { $returnBool = false; }
  11. return $returnBool; }

以上是关于检查日期是过去还是将来的主要内容,如果未能解决你的问题,请参考以下文章

Moment JS - 检查日期是今天还是将来

MySQL:查找过去或将来的最近日期

ios中从字符串到NSDate的日期转换

检查日期是不是在过去 Javascript

检查来自 db 的日期是不是从当前日期过去两周

aperiodoftimeinwhichsb开头加learn还是lessons