将当前日期与d / mm / yyyy格式的日期进行比较

将当前日期与d / mm / yyyy格式的日期进行比较

问题描述:

检查给定日期的最佳方式是什么?字符串d / mm / yyyy是否为过去?
当我使用strtotime(),它不能正常工作,因为非美国的符号。
当然,我可能会将日期作为字符串和比较子串进行处理,但必须有更好的方法。

What is the best way to check if a given date - a string d/mm/yyyy is a past? When I used strtotime(), it didn't work well, because of non-American notation. Of course I might deal with the dates as strings and compare substrings, but there has to be a better way.

if((strtotime('now')-strtotime($date)) > 86400) echo $date;



/ d / y或dmy格式通过查看
在各个组件之间的分隔符来消歧:如果分隔符是
斜杠(/),则假定为美国m / d / y;而如果
分隔符是破折号( - )或点(。),则假定为欧式dmy格式

Dates in the m/d/y or d-m-y formats are disambiguated by looking at the separator between the various components: if the separator is a slash (/), then the American m/d/y is assumed; whereas if the separator is a dash (-) or a dot (.), then the European d-m-y format is assumed.

strtotime()手册

所以一个简单的 str_replace('/',' - ',$ date)应该这样做。

So a simple str_replace('/', '-', $date) should do the trick.